@@ -4,34 +4,78 @@ const headers = require("markdown-it-github-headings")
4
4
const js = require ( "@jamshop/eleventy-plugin-esbuild" )
5
5
const glob = require ( "glob" )
6
6
const path = require ( "node:path" )
7
- const highlight = require ( "@11ty/eleventy-plugin-syntaxhighlight " )
7
+ const fs = require ( "node:fs/promises " )
8
8
const rss = require ( "@11ty/eleventy-plugin-rss" )
9
9
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
+ }
10
21
11
22
module . exports = ( eleventyConfig ) => {
12
23
eleventyConfig . addPlugin ( rss )
13
24
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
+ // })
19
61
20
62
eleventyConfig . addFilter ( "iso8601" , rss . dateToRfc3339 )
21
63
eleventyConfig . addFilter ( "date_to_rfc3339" , rss . dateToRfc3339 )
22
64
eleventyConfig . addFilter ( "date_to_rfc822" , rss . dateToRfc822 )
23
65
eleventyConfig . addFilter ( "html_to_absolute_urls" , rss . convertHtmlToAbsoluteUrls )
24
66
eleventyConfig . addFilter ( "domain" , ( str ) => new URL ( str ) . hostname )
25
67
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 )
35
79
36
80
eleventyConfig . addPassthroughCopy ( "images" )
37
81
eleventyConfig . addPassthroughCopy ( "browserconfig.xml" )
0 commit comments