File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,20 @@ let markdownItAnchorOptions = {
78
78
) ;
79
79
} ) ;
80
80
81
+ eleventyConfig . addFilter ( "esmToCjs" , async ( sourceCode ) => {
82
+ const { ImportTransformer } = await import ( 'esm-import-transformer' ) ;
83
+ try {
84
+ let it = new ImportTransformer ( sourceCode ) ;
85
+ let outputCode = it . transformToRequire ( ) ;
86
+
87
+ // lol
88
+ return outputCode . replace ( "export default " , "module.exports = " ) ;
89
+ } catch ( e ) {
90
+ console . log ( sourceCode ) ;
91
+ throw e ;
92
+ }
93
+ } ) ;
94
+
81
95
eleventyConfig . addNunjucksFilter ( "getDocumentsFromCollection" , function ( collection , value ) {
82
96
const docs = collection . filter ( doc => doc . data . repo === value )
83
97
return docs
Original file line number Diff line number Diff line change
1
+ {# This code is borrowed from the 11ty docs website #}
2
+ <seven-minute-tabs persist =" persist" sync =" sync" >
3
+ <ol role =" tablist" aria-label =" Select to view response for green, and not green URLs." >
4
+ <li >
5
+ <a href =" {{ tabid }}-esm" role =" tab" data-tabs-persist =" group:esm" tabindex =" -1" aria-controls =" {{ tabid }}-esm" >ESM</a >
6
+ </li >
7
+ <li >
8
+ <a href =" {{ tabid }}-cjs" role =" tab" data-tabs-persist =" group:cjs" tabindex =" -1" aria-controls =" {{ tabid }}-cjs" >CommonJS</a >
9
+ </li >
10
+ </ol >
11
+ <div id =" {{ tabid }}-esm" role =" tabpanel" >
12
+ {% highlight " js" %}
13
+ {%- if codeContent %}
14
+ {{ codeContent | safe }}
15
+ {% endif %}
16
+ {% endhighlight %}
17
+ </div >
18
+ <div id =" {{ tabid }}-cjs" role =" tabpanel" >
19
+ {% highlight " js" %}
20
+ {%- if codeContentCjs %}
21
+ {{ codeContentCjs | safe }}
22
+ {%- else if codeContent %}
23
+ {{ codeContent | esmToCjs | safe }}
24
+ {% endif %}
25
+ {% endhighlight %}
26
+ </div >
27
+ </seven-minute-tabs >
You can’t perform that action at this time.
0 commit comments