Skip to content

Commit b260bfb

Browse files
Switch to 11ty (#16)
1 parent 8b3271c commit b260bfb

45 files changed

Lines changed: 7281 additions & 4585 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules
2+
.DS_Store
3+
Thumbs.db
4+
5+
# Generated files
6+
*.html
7+
8+
# Cache
9+
.cache

.prettierrc.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
{
3+
"plugins": [
4+
"prettier-plugin-brace-style",
5+
"prettier-plugin-space-before-function-paren",
6+
"prettier-plugin-merge"
7+
],
8+
"braceStyle": "stroustrup",
9+
"arrowParens": "avoid",
10+
"bracketSpacing": true,
11+
"endOfLine": "auto",
12+
"semi": true,
13+
"singleQuote": false,
14+
"tabWidth": 4,
15+
"useTabs": true,
16+
"trailingComma": "all",
17+
"printWidth": 100
18+
}

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.defaultFormatter": "esbenp.prettier-vscode",
4+
"prettier.enable": true,
5+
"debug.enableStatusBarColor": false
6+
}

README.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"layout": "home.njk",
3+
"resources": [
4+
"https://plugins.prismjs.com/keep-markup/prism-keep-markup.js",
5+
"https://dev.prismjs.com/components/prism-bash.js"
6+
]
7+
}

README.md

Lines changed: 303 additions & 0 deletions
Large diffs are not rendered by default.

_build/eleventy.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import markdownItAnchor from "markdown-it-anchor";
2+
import markdownItAttrs from "markdown-it-attrs";
3+
import markdownItDeflist from "markdown-it-deflist";
4+
import pluginTOC from "eleventy-plugin-toc";
5+
import * as filters from "./filters.js";
6+
7+
import components from "prismjs/components.json" with { type: "json" };
8+
9+
export default config => {
10+
let data = {
11+
components,
12+
layout: "page.njk",
13+
autoloader: true,
14+
theme_switcher: true,
15+
toc: true,
16+
permalink: `{{ "index" if page.filePathStem == "/README" else page.filePathStem }}.html`,
17+
};
18+
19+
for (let p in data) {
20+
config.addGlobalData(p, data[p]);
21+
}
22+
23+
for (let f in filters) {
24+
config.addFilter(f, filters[f]);
25+
}
26+
27+
config.amendLibrary("md", md => {
28+
md.options.typographer = true;
29+
md.options.linkify = true;
30+
md.use(markdownItAnchor, {
31+
permalink: markdownItAnchor.permalink.headerLink(),
32+
});
33+
md.use(markdownItAttrs);
34+
md.use(markdownItDeflist);
35+
36+
// Allow setting attributes on the outer <pre>, not the inner <code>
37+
md.renderer.rules.fence = function (tokens, idx, options, env, slf) {
38+
let token = tokens[idx];
39+
let lang = token.info ? `class="language-${token.info}"` : "";
40+
let content = md.utils.escapeHtml(token.content).trim();
41+
return `<pre ${slf.renderAttrs(token)}><code ${lang}>${content}</code></pre>`;
42+
};
43+
});
44+
45+
config.addPlugin(pluginTOC, {
46+
tags: ["h1", "h2", "h3"],
47+
ul: true,
48+
});
49+
50+
return {
51+
markdownTemplateEngine: "njk",
52+
templateFormats: ["md", "njk"],
53+
dir: {
54+
layouts: "_layouts",
55+
output: ".",
56+
},
57+
};
58+
};

_build/filters.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import * as path from "path";
2+
3+
export function relative (page) {
4+
if (!page.url) {
5+
return "";
6+
}
7+
8+
let pagePath = page.url.replace(/[^/]+$/, "");
9+
let ret = path.relative(pagePath, "/");
10+
11+
return ret || ".";
12+
}
13+
14+
export function back_to_top (content) {
15+
// Add “↑ Back to top” at the end of each `<section>`
16+
return content.replace(/<\/section>/g, `<p><a href="#toc" class="back-to-top">↑ Back to top</a></p></section>`);
17+
}
18+
19+
export function pretty_size (size) {
20+
return Math.round(100 * size / 1024) / 100 + "KB";
21+
}
22+
23+
export function parse_resources (resources = []) {
24+
let ret = [];
25+
26+
resources = Array.isArray(resources) ? resources : [resources];
27+
for (let resource of resources) {
28+
resource = resource.trim();
29+
let url = resource;
30+
31+
// Attributes are defined as in markdown-it-attrs but we don't parse them and use them as-is.
32+
// For example: `{ data-autoloader-path="https://dev.prismjs.com/components/" }`
33+
let attributes = resource.match(/\{.*\}$/)?.[0];
34+
if (!attributes) {
35+
attributes = "";
36+
}
37+
else {
38+
url = url.replace(attributes, "").trim();
39+
attributes = attributes.slice(1, -1).trim(); // remove the curly braces
40+
}
41+
42+
let extension = url.match(/\.([^.]+)$/)?.[1];
43+
if (extension === "js" || extension === "mjs") {
44+
ret.push(`<script src="${url}" ${attributes}></script>`);
45+
}
46+
else if (extension === "css") {
47+
ret.push(`<link rel="stylesheet" href="${url}" ${attributes} />`);
48+
}
49+
else {
50+
// Raw HTML
51+
ret.push(url);
52+
}
53+
}
54+
55+
return ret;
56+
}

_data/eleventyComputed.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
export default {
2+
plugins (data) {
3+
let plugins = { ...data.components.plugins };
4+
delete plugins.meta;
5+
return plugins;
6+
},
7+
themes (data) {
8+
let themes = { ...data.components.themes };
9+
delete themes.meta;
10+
return themes;
11+
},
12+
languages (data) {
13+
let languages = { ...data.components.languages };
14+
delete languages.meta;
15+
16+
for (let id in languages) {
17+
let ret = [id];
18+
let alias = languages[id].alias;
19+
if (alias) {
20+
ret = ret.concat(Array.isArray(alias) ? alias : [alias]);
21+
}
22+
languages[id].alias = ret;
23+
}
24+
25+
return languages;
26+
},
27+
title (data) {
28+
if (data.title) {
29+
return data.title;
30+
}
31+
32+
let path = data.page.inputPath;
33+
path = path.slice(2);
34+
35+
let title = path.replace(".md", "");
36+
if (title === "README") {
37+
return;
38+
}
39+
40+
title = title.replace(/-/g, " ");
41+
42+
return title[0].toUpperCase() + title.slice(1);
43+
},
44+
files_sizes (data) {
45+
let ret = {};
46+
for (let file of data.tree) {
47+
ret[file.path] = file.size;
48+
}
49+
return ret;
50+
},
51+
};

_data/tree.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Fetch from "@11ty/eleventy-fetch";
2+
3+
export default async () => {
4+
let repo = await Fetch(
5+
// TODO: Replace with "https://api.github.com/repos/PrismJS/prism/git/trees/main?recursive=1" when v2 is launched
6+
"https://api.github.com/repos/PrismJS/prism/git/trees/master?recursive=1",
7+
{
8+
duration: "1d",
9+
type: "json",
10+
},
11+
);
12+
13+
return repo.tree;
14+
};

_layouts/home.njk

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{% extends "./page.njk" %}
2+
3+
{% block head_extra -%}
4+
<script>
5+
// Just a lil’ script to show off that inline JS gets highlighted
6+
console.log("foo");
7+
</script>
8+
{%- endblock %}
9+
10+
{% block header_extra -%}
11+
<ul id="features">
12+
<li>
13+
<strong>Dead simple</strong>
14+
Include prism.css and prism.js, use proper HTML5 code tags (<code>code.language-xxxx</code>), done!
15+
</li>
16+
<li>
17+
<strong>Intuitive</strong>
18+
Language classes are inherited so you can only define the language once for multiple code snippets.
19+
</li>
20+
<li>
21+
<strong>Light as a feather</strong>
22+
The core is 2KB minified &amp; gzipped. Languages add 0.3-0.5KB each, themes are around 1KB.
23+
</li>
24+
<li>
25+
<strong>Blazing fast</strong>
26+
Supports parallelism with Web Workers, if available.
27+
</li>
28+
<li>
29+
<strong>Extensible</strong>
30+
Define new languages or extend existing ones. Add new features thanks to Prism’s plugin architecture.
31+
</li>
32+
<li>
33+
<strong>Easy styling</strong>
34+
All styling is done through CSS, with sensible class names like <code>.comment</code>, <code>.string</code>, <code>.property</code> etc
35+
</li>
36+
</ul>
37+
{%- endblock %}

0 commit comments

Comments
 (0)