Skip to content

Commit 7a600a4

Browse files
committed
fix(docs): community templates
1 parent 0a7a963 commit 7a600a4

File tree

1 file changed

+119
-1
lines changed

1 file changed

+119
-1
lines changed

source/templates/community/README.md

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,124 @@ with:
7676
7777
```
7878
<!--/examples-->
79+
80+
## 📪 Creating community templates
81+
82+
Templates creation requires you to be comfortable with HTML, CSS and JavaScript ([EJS](https://github.com/mde/ejs) flavored).
83+
84+
To create a new template, clone and setup this repository first:
85+
```shell
86+
git clone https://github.com/lowlighter/metrics.git
87+
cd metrics/
88+
npm install
89+
```
90+
91+
Find a cool name for your new template and run the following:
92+
```shell
93+
npm run quickstart template <template_name>
94+
```
95+
96+
It will create a new directory in `/source/templates` with the following file structure:
97+
* `/source/templates/{template-name}`
98+
* `README.md`,
99+
* `metadata.yml`,
100+
* `image.svg`
101+
* `partials/`
102+
* `_.json`
103+
* `*.ejs`
104+
105+
Templates are auto-loaded based on their folder existence, so there's no need to register them somewhere.
106+
107+
### 💬 Understanding `image.svg`
108+
109+
Usually `image.svg` doesn't need to be edited too much, but let's explain it how it works.
110+
111+
```html
112+
<svg xmlns="http://www.w3.org/2000/svg" width="480" height="99999" class="<%= !animated ? 'no-animations' : '' %>">
113+
114+
<defs><style><%= fonts %></style></defs>
115+
<style data-optimizable="true"><%= style %></style>
116+
117+
<foreignObject x="0" y="0" width="100%" height="100%">
118+
<div xmlns="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink">
119+
<% for (const partial of [...partials]) { %>
120+
<%- await include(`partials/${partial}.ejs`) %>
121+
<% } %>
122+
123+
<div id="metrics-end"></div>
124+
</div>
125+
</foreignObject>
126+
127+
</svg>
128+
```
129+
130+
#### EJS syntax
131+
132+
[EJS](https://github.com/mde/ejs) framework is used to programmatically create content through the help of templating tags (`<% %>`).
133+
134+
#### Styling
135+
136+
`fonts` and `style` variables are respectively populated with `fonts.css` and `styles.css` files content (or will fallback to those of `classic` template inexistent).
137+
138+
These will define the global design of the output.
139+
140+
`data-optimizable="true"` tells that a `style` tag can be safely minified and purged by CSS post-processors.
141+
142+
#### Partials
143+
144+
`partials` variable is populated with `partials/_.json` file content and define which files should be included along with default ordering.
145+
146+
The loop iterates over this array to include all defined partials. Each partial should handle whether it should be displayed by itself.
147+
148+
### `#metrics-end` tag
149+
150+
`#metrics-end` is a special HTML tag which must remain at the bottom of SVG template.
151+
152+
It is used to compute height dynamically through a [puppeteer](https://github.com/puppeteer/puppeteer) headless instance. Initial height should remain a high number so it doesn't get cropped accidentally while [puppeteer](https://github.com/puppeteer/puppeteer) compute [element.getBoundingClientRect()](https://developer.mozilla.org/fr/docs/Web/API/Element/getBoundingClientRect).
153+
154+
### 💬 Filling `metadata.yml`
155+
156+
`metadata.yml` is a file which describes supported account types, output formats, scopes, etc.
157+
158+
```yaml
159+
name: "🖼️ Template name"
160+
extends: classic
161+
description: Short description
162+
examples:
163+
default: https://via.placeholder.com/468x60?text=No%20preview%20available
164+
supports:
165+
- user
166+
- organization
167+
- repository
168+
formats:
169+
- svg
170+
- png
171+
- jpeg
172+
- json
173+
- markdown
174+
- markdown-pdf
175+
```
176+
177+
[`🧱 core`](/source/plugins/core/README.md) plugin will automatically check user inputs with your defined supported `supports` and `formats` key and throw an error in case of incompatibility.
178+
179+
`name`, `description` and `examples` are used to auto-generate documentation in the `README.md` by replacing the following:
180+
181+
```markdown
182+
<ǃ--header-->
183+
<ǃ--/header-->
184+
```
185+
186+
`extends` is used to define upon which template it should inherits its `template.mjs` when it is not trusted by user.
187+
188+
### 💬 Filling `examples.yml`
189+
190+
Workflow examples from `examples.yml` are used to auto-generate documentation in the `README.md` by replacing the following:
191+
192+
```markdown
193+
#### ℹ️ Examples workflows
194+
195+
<ǃ--examples-->
196+
<ǃ--/examples-->
79197
```
80198

81199
### 💬 Creating partials
@@ -111,4 +229,4 @@ Here's a quick step-by-step tutorial to create base64 encoded fonts:
111229
- 4. Convert them into base64 with `woff` format on [transfonter.org](https://transfonter.org)
112230
- 5. Download archive and extract it
113231
- 6. Copy content of generated stylesheet to `fonts.css`
114-
- 7. Update `style.css` to use the new font
232+
- 7. Update `style.css` to use the new font

0 commit comments

Comments
 (0)