Skip to content

Commit 398268c

Browse files
koddssonkeithamus
andcommitted
WIP
Co-authored-by: Keith Cirkel <[email protected]>
1 parent d2c5556 commit 398268c

File tree

7 files changed

+1802
-10507
lines changed

7 files changed

+1802
-10507
lines changed

.eleventy.js

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,78 @@ const headers = require("markdown-it-github-headings")
44
const js = require("@jamshop/eleventy-plugin-esbuild")
55
const glob = require("glob")
66
const path = require("node:path")
7-
const highlight = require("@11ty/eleventy-plugin-syntaxhighlight")
7+
const fs = require("node:fs/promises")
88
const rss = require("@11ty/eleventy-plugin-rss")
99
const dedent = require("dedent")
10+
const { build } = require("esbuild");
11+
12+
const buildJS = (config = {}) => {
13+
return build({
14+
minify: process.NODE_ENV === "development" ? false : true,
15+
bundle: true,
16+
write: true,
17+
outdir: '_site/script',
18+
...config,
19+
});
20+
}
1021

1122
module.exports = (eleventyConfig) => {
1223
eleventyConfig.addPlugin(rss)
1324
eleventyConfig.addPlugin(css)
14-
eleventyConfig.addPlugin(js, {
15-
entryPoints: Object.fromEntries(glob.sync("script/*.[tj]s").map((e) => [path.basename(e, path.extname(e)), e])),
16-
output: "_site/script",
17-
})
18-
eleventyConfig.addPlugin(highlight)
25+
26+
const entryPoints = glob.sync("script/*.[tj]s")
27+
eleventyConfig.addWatchTarget("script/*.[tj]s")
28+
29+
buildJS({entryPoints})
30+
31+
eleventyConfig.on("beforeWatch", (changedFiles) => {
32+
// Run me before --watch or --serve re-runs
33+
if(entryPoints.some(watchPath => changedFiles.includes(watchPath))) {
34+
buildJS({entryPoints})
35+
}
36+
});
37+
38+
// eleventyConfig.addPlugin(js, {
39+
// entryPoints: glob.sync("script/*.[tj]s"),
40+
// outDir: "_site/script",
41+
// esbuild: {
42+
// plugins: [
43+
// {
44+
// name: "css",
45+
// setup: (plugin) => {
46+
// console.log('==================>')
47+
// plugin.onResolve({filter: /^.*\.css$/}, (ctx) => Object.assign(ctx, {namespace: 'css'}))
48+
// plugin.onLoad({filter: /^.*\.css$/, namespace: 'css'}, async (ctx) => {
49+
// let contents = await fs.readFileSync(path.resolve(ctx.resolveDir, ctx.filePath), 'utf8')
50+
51+
// contents = `const c = new CSSStyleSheet(); c.replaceSync("${contents}"); export default c;`
52+
53+
// return {contents, resolveDir: ctx.resolveDir}
54+
// })
55+
// }
56+
// }
57+
// ],
58+
// minify: false
59+
// }
60+
// })
1961

2062
eleventyConfig.addFilter("iso8601", rss.dateToRfc3339)
2163
eleventyConfig.addFilter("date_to_rfc3339", rss.dateToRfc3339)
2264
eleventyConfig.addFilter("date_to_rfc822", rss.dateToRfc822)
2365
eleventyConfig.addFilter("html_to_absolute_urls", rss.convertHtmlToAbsoluteUrls)
2466
eleventyConfig.addFilter("domain", (str) => new URL(str).hostname)
2567

26-
eleventyConfig.setLibrary(
27-
"md",
28-
markdown({
29-
html: true,
30-
linkify: true,
31-
})
32-
.use(headers, { prefixHeadingIds: false })
33-
.disable("code")
34-
)
68+
const md = markdown({
69+
html: true,
70+
linkify: true,
71+
highlight: (str, lang) => {
72+
return `<pre><code-interactive lang="${lang}">${md.utils.escapeHtml(str)}</code-interactive></pre>`
73+
},
74+
})
75+
.use(headers, { prefixHeadingIds: false })
76+
.disable("code")
77+
78+
eleventyConfig.setLibrary("md", md)
3579

3680
eleventyConfig.addPassthroughCopy("images")
3781
eleventyConfig.addPassthroughCopy("browserconfig.xml")

_includes/main.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
<link rel="stylesheet" href="/css/{{file}}" />
3636
{% endfor %}
3737
<link href="/feed.xml" rel="alternate" type="application/atom+xml" title="Web Components Guide Blog" />
38+
39+
<script type="module" defer src="/script/polyfills.js"></script>
40+
{% for file in script %}
41+
<script type="module" defer src="/script/{{ file }}"></script>
42+
{% endfor %}
3843
</head>
3944
<body>
4045
{% include 'header.html' %} {% include 'navigation.html' %}
@@ -49,10 +54,5 @@
4954
</ol>
5055
</nav>
5156
</footer>
52-
53-
<script type="module" src="/script/polyfills.js"></script>
54-
{% for file in script %}
55-
<script type="module" src="/script/{{ file }}"></script>
56-
{% endfor %}
5757
</body>
5858
</html>

css/code-interactive.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:host {
2+
background-color: hotpink;
3+
}

0 commit comments

Comments
 (0)