Skip to content

Commit b8995a4

Browse files
authored
chore: Implement docs site (#15815)
* chore: Implement docs site * Add _site to gitignore * Update gensite * Resolve duplicate permalinks * Address feedback
1 parent ab37d3b commit b8995a4

259 files changed

Lines changed: 14387 additions & 22 deletions

File tree

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/node_modules
2+
/docs/node_modules
23
test.js
34
coverage/
45
build/
@@ -26,3 +27,6 @@ versions.json
2627
yarn.lock
2728
package-lock.json
2829
pnpm-lock.yaml
30+
31+
# Docs site output
32+
_site

Makefile.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,18 @@ target.gensite = function(prereleaseVersion) {
622622

623623
// 3. Copy docs folder to a temporary directory
624624
echo("> Copying the docs folder (Step 3)");
625-
cp("-rf", "docs/src/*", TEMP_DIR);
625+
docFiles.forEach(filePath => {
626+
const pathToCopy = path.join("docs/src", filePath, "*"),
627+
tempPath = path.join(TEMP_DIR, filePath);
628+
629+
if (!test("-d", tempPath)) {
630+
mkdir(tempPath);
631+
}
632+
633+
cp("-rf", pathToCopy, tempPath);
634+
});
626635

627636
// special case (for now)
628-
cp("-f", "docs/src/pages/index.md", path.join(TEMP_DIR, "index.md"));
629637
rm("-rf", path.join(TEMP_DIR, "pages"));
630638

631639
let versions = test("-f", "./versions.json") ? JSON.parse(cat("./versions.json")) : {};

docs/.eleventy.js

Lines changed: 360 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,360 @@
1+
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
2+
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
3+
const pluginRss = require("@11ty/eleventy-plugin-rss");
4+
const pluginTOC = require('eleventy-plugin-nesting-toc');
5+
const slugify = require("slugify");
6+
const markdownIt = require("markdown-it");
7+
const markdownItAnchor = require('markdown-it-anchor');
8+
const Image = require("@11ty/eleventy-img");
9+
const metascraper = require('metascraper')([
10+
require('metascraper-image')(),
11+
require('metascraper-logo')(),
12+
require('metascraper-logo-favicon')(),
13+
require('metascraper-publisher')(),
14+
require('metascraper-title')(),
15+
require('metascraper-description')(),
16+
require('metascraper-url')()
17+
]);
18+
const got = require('got');
19+
const path = require('path');
20+
21+
const {
22+
DateTime
23+
} = require("luxon");
24+
25+
module.exports = function(eleventyConfig) {
26+
let now = new Date();
27+
28+
/*****************************************************************************************
29+
* Filters
30+
* ***************************************************************************************/
31+
eleventyConfig.addFilter("limitTo", function(arr, limit) {
32+
return arr.slice(0, limit);
33+
});
34+
35+
eleventyConfig.addFilter('jsonify', function(variable) {
36+
return JSON.stringify(variable);
37+
});
38+
39+
eleventyConfig.addFilter('slugify', function(str) {
40+
if (!str) {
41+
return;
42+
}
43+
44+
return slugify(str, {
45+
lower: true,
46+
strict: true,
47+
remove: /["]/g,
48+
});
49+
});
50+
51+
eleventyConfig.addFilter('URIencode', function(str) {
52+
if (!str) {
53+
return;
54+
}
55+
return encodeURI(str);
56+
});
57+
58+
/* order collection by the order specified in the front matter */
59+
eleventyConfig.addFilter("sortByPageOrder", function(values) {
60+
return values.slice().sort((a, b) => a.data.order - b.data.order);
61+
});
62+
63+
eleventyConfig.addFilter("readableDate", (dateObj) => {
64+
//turn it into a JS Date string
65+
date = new Date(dateObj);
66+
//pass it to luxon for formatting
67+
return DateTime.fromJSDate(date).toFormat('dd MMM, yyyy');
68+
});
69+
70+
eleventyConfig.addFilter("blogPermalinkDate", (dateObj) => {
71+
//turn it into a JS Date string
72+
date = new Date(dateObj);
73+
//pass it to luxon for formatting
74+
return DateTime.fromJSDate(dateObj).toFormat('yyyy/MM');
75+
});
76+
77+
eleventyConfig.addFilter("readableDateFromISO", (ISODate) => {
78+
return DateTime.fromISO(ISODate).toUTC().toLocaleString(DateTime.DATE_FULL);
79+
});
80+
81+
eleventyConfig.addFilter('dollars', value => {
82+
return new Intl.NumberFormat("en-US", {
83+
style: "currency",
84+
currency: "USD"
85+
}).format(value);
86+
});
87+
88+
// parse markdown from includes, used for author bios
89+
// Source: https://github.com/11ty/eleventy/issues/658
90+
eleventyConfig.addFilter('markdown', function(value) {
91+
let markdown = require('markdown-it')({
92+
html: true
93+
});
94+
return markdown.render(value);
95+
});
96+
97+
/*****************************************************************************************
98+
* Plugins
99+
* ***************************************************************************************/
100+
eleventyConfig.addPlugin(eleventyNavigationPlugin);
101+
eleventyConfig.addPlugin(syntaxHighlight, {
102+
alwaysWrapLineHighlights: true,
103+
});
104+
eleventyConfig.addPlugin(pluginRss);
105+
eleventyConfig.addPlugin(pluginTOC, {
106+
tags: ['h2', 'h3', 'h4'],
107+
wrapper: 'nav', // Element to put around the root `ol`
108+
wrapperClass: 'c-toc', // Class for the element around the root `ol`
109+
headingText: '', // Optional text to show in heading above the wrapper element
110+
headingTag: 'h2' // Heading tag when showing heading above the wrapper element
111+
});
112+
// add IDs to the headers
113+
const markdownIt = require('markdown-it');
114+
eleventyConfig.setLibrary("md",
115+
markdownIt({
116+
html: true,
117+
linkify: true,
118+
typographer: true,
119+
120+
}).use(markdownItAnchor, {}).disable('code')
121+
);
122+
123+
/**********************************************************************
124+
* Shortcodes
125+
* ********************************************************************/
126+
eleventyConfig.addNunjucksAsyncShortcode("link", async function(link) {
127+
const { body: html, url } = await got(link);
128+
const metadata = await metascraper({ html, url });
129+
130+
const encodedURL = encodeURIComponent(link);
131+
const the_url = (new URL(link)); // same as url
132+
const domain = the_url.hostname;
133+
134+
return `
135+
<article class="resource">
136+
<div class="resource__image">
137+
<img class="resource__img" width="75" height="75" src="${metadata.logo}" alt="Avatar image for ${domain}" />
138+
</div>
139+
<div class="resource__content">
140+
<a href="${metadata.url}" class="resource__title"> ${metadata.title} </a><br>
141+
<span class="resource__domain"> ${domain}</span>
142+
</div>
143+
<svg class="c-icon resource__icon" width="13" height="12" viewBox="0 0 13 12" fill="none">
144+
<path d="M1.5 11L11.5 1M11.5 1H1.5M11.5 1V11" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
145+
</svg>
146+
</article>`;
147+
});
148+
149+
eleventyConfig.addShortcode("fixable", function() {
150+
return `
151+
<div class="rule-category">
152+
<span class="rule-category__icon">🛠 <span class="visually-hidden">Fixable</span></span>
153+
<p class="rule-category__description">
154+
if some problems reported by the rule are automatically fixable by the <code>--fix</code> command line option
155+
</p>
156+
</div>`;
157+
});
158+
159+
eleventyConfig.addShortcode("recommended", function() {
160+
return `
161+
<div class="rule-category">
162+
<span class="rule-category__icon">✅ <span class="visually-hidden">Recommended</span></span>
163+
<p class="rule-category__description">
164+
if the <code>"extends": "eslint:recommended"</code> property in a configuration file enables the rule.
165+
</p>
166+
</div>`;
167+
});
168+
169+
eleventyConfig.addShortcode("hasSuggestions", function() {
170+
return `
171+
<div class="rule-category">
172+
<span class="rule-category__icon">💡 <span class="visually-hidden">hasSuggestions</span></span>
173+
<p class="rule-category__description">
174+
if some problems reported by the rule are manually fixable by editor suggestions
175+
</p>
176+
</div>`;
177+
});
178+
179+
eleventyConfig.addShortcode("related_rules", function(arr) {
180+
let rules = arr,
181+
items = "";
182+
183+
rules.forEach(function(rule) {
184+
let list_item = `<li class="related-rules__list__item">
185+
<a href="/rules/${rule}">
186+
<span>${rule}</span>
187+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" aria-hidden="true" focusable="false">
188+
<path d="M5 12H19M19 12L12 5M19 12L12 19" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
189+
</svg>
190+
</a>
191+
</li>`;
192+
items += list_item;
193+
})
194+
195+
return `
196+
<ul class="related-rules__list" role="list">
197+
${items}
198+
</ul>`;
199+
});
200+
201+
eleventyConfig.addShortcode("important", function(text, url) {
202+
return `
203+
<div role="note" class="alert alert--important">
204+
<svg class="alert__icon" aria-hidden="true" focusable="false" width="21" height="18" viewBox="0 0 21 18" fill="none">
205+
<path d="M10.4998 6.66666V9.99999M10.4998 13.3333H10.5081M9.0748 2.38333L2.01647 14.1667C1.87094 14.4187 1.79394 14.7044 1.79313 14.9954C1.79231 15.2864 1.86771 15.5726 2.01183 15.8254C2.15594 16.0783 2.36374 16.2889 2.61456 16.4365C2.86538 16.5841 3.15047 16.6635 3.44147 16.6667H17.5581C17.8491 16.6635 18.1342 16.5841 18.385 16.4365C18.6359 16.2889 18.8437 16.0783 18.9878 15.8254C19.1319 15.5726 19.2073 15.2864 19.2065 14.9954C19.2057 14.7044 19.1287 14.4187 18.9831 14.1667L11.9248 2.38333C11.7762 2.13841 11.5671 1.93593 11.3175 1.7954C11.0679 1.65487 10.7862 1.58104 10.4998 1.58104C10.2134 1.58104 9.93175 1.65487 9.68214 1.7954C9.43254 1.93593 9.22336 2.13841 9.0748 2.38333Z" stroke="currentColor" stroke-width="1.66667" stroke-linecap="round" stroke-linejoin="round" />
206+
</svg>
207+
<div class="alert__content">
208+
<span class="alert__type">Important</span>
209+
<div class="alert__text">${text}</div>
210+
<a href="${url}" class="alert__learn-more">Learn more</a>
211+
</div>
212+
</div>`;
213+
});
214+
215+
eleventyConfig.addShortcode("warning", function(text, url) {
216+
return `
217+
<div role="note" class="alert alert--warning">
218+
<svg class="alert__icon" aria-hidden="true" focusable="false" width="19" height="20" viewBox="0 0 19 20" fill="none">
219+
<path d="M9.49999 6.66667V10M9.49999 13.3333H9.50832M17.8333 10C17.8333 14.6024 14.1024 18.3333 9.49999 18.3333C4.89762 18.3333 1.16666 14.6024 1.16666 10C1.16666 5.39763 4.89762 1.66667 9.49999 1.66667C14.1024 1.66667 17.8333 5.39763 17.8333 10Z" stroke="currentColor" stroke-width="1.66667" stroke-linecap="round" stroke-linejoin="round" />
220+
</svg>
221+
<div class="alert__content">
222+
<span class="alert__type">Warning</span>
223+
<div class="alert__text">${text}</div>
224+
<a href="${url}" class="alert__learn-more">Learn more</a>
225+
</div>
226+
</div>`;
227+
});
228+
229+
eleventyConfig.addShortcode("tip", function(text, url) {
230+
return `
231+
<div role="note" class="alert alert--tip">
232+
<svg class="alert__icon" aria-hidden="true" focusable="false" width="19" height="20" viewBox="0 0 19 20" fill="none">
233+
<path d="M17.8333 9.23333V10C17.8323 11.797 17.2504 13.5456 16.1744 14.9849C15.0985 16.4241 13.5861 17.4771 11.8628 17.9866C10.1395 18.4961 8.29771 18.4349 6.61205 17.8122C4.92639 17.1894 3.4872 16.0384 2.50912 14.5309C1.53105 13.0234 1.06648 11.2401 1.18472 9.44693C1.30296 7.6538 1.99766 5.94694 3.16522 4.58089C4.33278 3.21485 5.91064 2.26282 7.66348 1.86679C9.41632 1.47076 11.2502 1.65195 12.8917 2.38333M17.8333 3.33333L9.49999 11.675L6.99999 9.175" stroke="currentColor" stroke-width="1.66667" stroke-linecap="round" stroke-linejoin="round" />
234+
</svg>
235+
<div class="alert__content">
236+
<span class="alert__type">Tip</span>
237+
<div class="alert__text">${text}</div>
238+
<a href="${url}" class="alert__learn-more">Learn more</a>
239+
</div>
240+
</div>`;
241+
});
242+
243+
244+
eleventyConfig.addWatchTarget("./src/assets/");
245+
246+
247+
248+
/*****************************************************************************************
249+
* File PassThroughs
250+
* ***************************************************************************************/
251+
252+
eleventyConfig.addPassthroughCopy({
253+
"./src/static": "/"
254+
});
255+
256+
eleventyConfig.addPassthroughCopy('./src/assets/');
257+
258+
eleventyConfig.addPassthroughCopy({
259+
'./src/content/**/*.png': "/assets/images"
260+
});
261+
262+
eleventyConfig.addPassthroughCopy({
263+
'./src/content/**/*.jpg': "/assets/images"
264+
});
265+
266+
eleventyConfig.addPassthroughCopy({
267+
'./src/content/**/*.jpeg': "/assets/images"
268+
});
269+
270+
eleventyConfig.addPassthroughCopy({
271+
'./src/content/**/*.svg': "/assets/images"
272+
});
273+
274+
eleventyConfig.addPassthroughCopy({
275+
'./src/content/**/*.mp4': "/assets/videos"
276+
});
277+
278+
eleventyConfig.addPassthroughCopy({
279+
'./src/content/**/*.pdf': "/assets/documents"
280+
});
281+
282+
eleventyConfig.addPassthroughCopy({
283+
'./node_modules/algoliasearch/dist/algoliasearch-lite.esm.browser.js': "/assets/js/algoliasearch.js"
284+
});
285+
286+
/*****************************************************************************************
287+
* Collections
288+
* ***************************************************************************************/
289+
290+
eleventyConfig.addCollection("docs", function(collection) {
291+
return collection.getFilteredByGlob("./src/**/**/*.md");
292+
});
293+
294+
eleventyConfig.addCollection("library", function(collection) {
295+
return collection.getFilteredByGlob("./src/library/**/*.md");
296+
});
297+
298+
299+
// START, eleventy-img
300+
function imageShortcode(src, alt, cls, sizes = "(max-width: 768px) 100vw, 50vw") {
301+
const source = src;
302+
// console.log(`Generating image(s) from: ${src}`)
303+
let options = {
304+
widths: [600, 900, 1500],
305+
formats: ["webp", "jpeg"],
306+
urlPath: "/assets/images/",
307+
outputDir: "./_site/assets/images/",
308+
filenameFormat: function(id, src, width, format, options) {
309+
const extension = path.extname(src)
310+
const name = path.basename(src, extension)
311+
return `${name}-${width}w.${format}`
312+
}
313+
}
314+
315+
function getSRC() {
316+
if (source.indexOf("http://") == 0 || source.indexOf("https://") == 0) {
317+
return source;
318+
} else {
319+
// for convenience, you only need to use the image's name in the shortcode,
320+
// and this will handle appending the full path to it
321+
src = path.join('./src/assets/images/', source);
322+
return src;
323+
}
324+
}
325+
326+
var fullSrc = getSRC();
327+
// generate images
328+
Image(fullSrc, options)
329+
330+
let imageAttributes = {
331+
alt,
332+
class: cls,
333+
sizes,
334+
loading: "lazy",
335+
decoding: "async",
336+
}
337+
// get metadata
338+
metadata = Image.statsSync(fullSrc, options)
339+
return Image.generateHTML(metadata, imageAttributes)
340+
}
341+
eleventyConfig.addShortcode("image", imageShortcode)
342+
// END, eleventy-img
343+
344+
345+
return {
346+
passthroughFileCopy: true,
347+
348+
markdownTemplateEngine: 'njk',
349+
dataTemplateEngine: 'njk',
350+
htmlTemplateEngine: 'njk',
351+
352+
dir: {
353+
input: "src",
354+
includes: "_includes",
355+
layouts: "_includes/layouts",
356+
data: "_data",
357+
output: "_site"
358+
}
359+
};
360+
};

0 commit comments

Comments
 (0)