ai2html is an open-source script for Adobe Illustrator that converts your Illustrator documents into html and css.
The Axios version of ai2html has been customized for the Axios Visuals workflow, including the exporting of fallback images and the ability to export a project as a svelte component (ai2svelte
). See Notion for some additional tips and tricks to using AI.
For documentation and examples on how to use ai2html in general, please visit ai2html.org.
Copy ai2html.js
to the Applications/[Adobe Illustrator]/Presets/en_US/Scripts
directory (select the version of the software you use).
- Copy the
yyyy-mm-dd-slug
directory template from the team Drive folder to your project. - Rename the folder and the
yyyy-mm-dd-slug.ai
file. The name of the.ai
file will be the name of your built/processed project. - Create your graphics using the artboards provided
- In the
ai2html-settings
block, set youralt
text. - When you're ready, run
ai2html
(File --> Scripts --> ai2html) - When the script runs, you should need a new directory called
/[slug]
in your project folder that contains:
[slug].html
- your embed HTML[slugInPascalCase].svelte
- your Svelte component/images/
- Images directory that contains all the background images needed to render the graphic/fallbacks/
- Directory that contains the fallback images of the mobile large, tablet, social and instagram artboards.
- Upload the output
/[slug]
directory to the graphics server
Swap out both URLs with your GitHub pages URL and embed into Prism!
<div id="chart"></div> <script type="text/javascript" src="https://pym.nprapps.org/pym.v1.min.js" ></script> <script> var pymParent = new pym.Parent( "chart", "https://cbs-news-data.github.io/teacher-shortages_ai2html/", {} ); </script> <amp-iframe width="100" height="100" layout="responsive" sandbox="allow-scripts allow-same-origin" resizable src="https://cbs-news-data.github.io/teacher-shortages_ai2html/"> <div overflow tabindex="0" role="button" aria-label="View more"> </div> </amp-iframe>
Running the ai2html
script will automatically generate a .svelte
component for you. To add the component to the project, follow these instructions/tips:
- Copy the
/[slug]
output directory to your components directory in your Svelte project and rename accordingly. Depending on your project structure, that might look like/src/lib/components/[slugInPascalCase]
. - Optionally, delete the
[slug].html
file from your Svelte project. - Import the AI component and use in your project
<script>
import WorldMap from "components/WorldMap/WorldMap.svelte"
</script>
<WorldMap />
If your Svelte project is not already set up to use svelte-preprocess-import-assets
, install it and add it to your project's svelte.config.js
file.
import importAssets from "svelte-preprocess-import-assets";
const config = {
kit: {
// Kit options here
},
preprocess: [
preprocess({
// Svelte preprocess options here
}),
importAssets(),
],
};
Tips:
- If you want to generate just the
svelte
output, setproject_type: svelte
in the settings - When updating the project slug, use title-case/pascal-case naming (eg.
WorldMap/WorldMap.ai
) - We recommend not including the hed or dek of the chart in the artboards. Instead, you can set it in Svelte.
- You may create additional artboards if you need other sizes
- You may increase the height of all the artboards, except for the social and instagram artboards
- Artboards that are named
-[name]
will not be included in the output
If you need to modify any of the default settings, you can do so by creating an ai2html-config.json
file in your project folder or by modifying the ai2html-settings
block in the .ai
file. See ai2html.org for details.
To add custom fonts to a project, we recommend using an ai2html-config.json
file. To use a custom font, add the font information to the fonts
array, like this:
ai2html-config.json
{
"fonts": [
{
"aifont": "CCMeanwhile",
"family": "ccmeanwhile, sans-serif",
"weight": "",
"style": ""
}
]
}
Save ai2html-config.json
to the same directory as your .ai
file.
In order to add fonts to the array, you'll need to know the Illustrator name for the font files. If you haven't already, save /utilities/aifontname.js
to Applications/[Adobe Illustrator]/Presets/en_US/Scripts
.
With your .ai
file open in Illustrator, go to File --> Scripts --> aifontname
. This will generate a popup in AI of the fonts used. These are the names you want to use in the fonts
array.
If you're loading in fonts from Adobe Fonts/Typekit/Google Fonts, you must also:
- Add fonts to Creative Cloud (Adobe Fonts only)
- Sign in to https://fonts.adobe.com
- Find the custom fonts needed for the project and mark them as "active". This should sync them to your local computer using Creative Cloud.
- Add to or create a new Web Project
- Note: Only include the fonts/font weights you'll actually be using in the Web Project. Every new font/weight/style increases the overall page load time. This is different from the fonts you have active on your local computer.
- At the bottom of the
<head>
section oftemplate.html
, add the embed code provided by Adobe Fonts/Google fonts/etc. Add it before you run theai2html
script and it will be included automatically.
<link rel="stylesheet" href="https://use.typekit.net/vlt1eba.css">
- If adding to a Svelte project, add the embed code to
style.scss
.
The Github repository for this site is available at newsdev/ai2html.
Many thanks to Gregor Aisch, Derek Watkins, Josh Katz, K.K. Rebecca Lai, Tom Giratikanon, Matt Ericson, Jeremy Ashkenas and Alan McLean for their incredible contributions to this project, as well as to my colleagues in The New York Times Graphics Department for their patient guidance.
If you’re learning to write Javascript for Adobe Illustrator, John Wundes, has many wonderful scripts. explore.js is particularly helpful for understanding what attributes are attached to Illustrator objects.
Created by Archie Tse / The New York Times
Copyright (c) 2011-2015 The New York Times Company