|
| 1 | +# Figma REST API HTML Generator |
| 2 | + |
| 3 | +Generate HTML files from files fetched through the |
| 4 | +[Figma REST API](https://www.figma.com/developers/api). |
| 5 | + |
| 6 | +## Example output discussed |
| 7 | + |
| 8 | +[example](../../example-figma-files/gov-uk-design-system-components/button.html) |
| 9 | + |
| 10 | +```html |
| 11 | +<div |
| 12 | + style=" |
| 13 | + color: #fff; |
| 14 | + font-family: GDS Transport Website; |
| 15 | + font-size: 19px; |
| 16 | + font-weight: 300; |
| 17 | + line-height: 25px; |
| 18 | + " |
| 19 | + data-figma-name="Content: Text" |
| 20 | + data-figma-id="1:9" |
| 21 | +> |
| 22 | + Button |
| 23 | +</div> |
| 24 | +``` |
| 25 | + |
| 26 | +The CSS used to format the HTML is inline on each HTML tag. No attempt is yet |
| 27 | +made to use CSS stylesheets or assign helpers like CSS classes. |
| 28 | + |
| 29 | +Some absolute positioning and absolute sizing is used where it can't be avoided. |
| 30 | +Using |
| 31 | +[auto-layout](https://help.figma.com/hc/en-us/articles/5731482952599-Using-auto-layout) |
| 32 | +mostly prevents that as it gets converted to flex-box. |
| 33 | + |
| 34 | +The HTML maps directly to nodes within Figma. A deeply nested Figma design will |
| 35 | +generate deeploy nested html. |
| 36 | + |
| 37 | +No fallback fonts are specified. |
| 38 | + |
| 39 | +Vectors are replaced by an SVG placeholder. |
| 40 | + |
| 41 | +## Direction |
| 42 | + |
| 43 | +I'm undecided to if this is going to be: |
| 44 | + |
| 45 | +- A general purpose HTML generator. |
| 46 | +- A generator designed to adapt to peculiarities of a few designs (for example |
| 47 | + ones I use at work). |
| 48 | +- A tool designed to be flexible with lots of configuration. |
| 49 | +- An inspiration from which other generators can be built. These could even in |
| 50 | + other languages like TypeScript since I generate types. |
| 51 | + |
| 52 | +## Usage |
| 53 | + |
| 54 | +```bash |
| 55 | +cargo run --release -- to-html 213:6 < example-figma-files/gov-uk-design-system.json > example-figma-files/gov-uk-design-system-components/button.html |
| 56 | +``` |
| 57 | + |
| 58 | +You can get the node id from the URL when using the web-ui. |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +The HTML can be piped through additional commands to add fallback fonts and to |
| 63 | +format the HTML. |
| 64 | + |
| 65 | +```bash |
| 66 | +cargo run --release -- to-html 213:6 < example-figma-files/gov-uk-design-system.json \ |
| 67 | + | sed 's/font-family: GDS Transport Website;/font-family: GDS Transport Website,arial,sans-serif;/g' \ |
| 68 | + | npx prettier@2.8.4 --parser html > example-figma-files/gov-uk-design-system-components/button.html |
| 69 | +``` |
0 commit comments