@@ -4,34 +4,78 @@ const headers = require("markdown-it-github-headings")
44const js = require ( "@jamshop/eleventy-plugin-esbuild" )
55const glob = require ( "glob" )
66const path = require ( "node:path" )
7- const highlight = require ( "@11ty/eleventy-plugin-syntaxhighlight " )
7+ const fs = require ( "node:fs/promises " )
88const rss = require ( "@11ty/eleventy-plugin-rss" )
99const 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
1122module . 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" )
0 commit comments