@@ -2,6 +2,7 @@ const fs = require("fs");
22const path = require ( "path" ) ;
33const { EleventyRenderPlugin } = require ( "@11ty/eleventy" ) ;
44const eleventyNavigationPlugin = require ( "@11ty/eleventy-navigation" ) ;
5+ const Nunjucks = require ( "nunjucks" ) ;
56
67function findFileInDir ( dir , filename ) {
78 let files = fs . readdirSync ( dir ) ;
@@ -20,6 +21,21 @@ function findFileInDir(dir, filename) {
2021 return null ;
2122}
2223
24+ function findSelfInNavPages ( navPages , url ) {
25+ for ( const page of navPages ) {
26+ console . log ( page . key ) ;
27+ if ( page . key == url ) {
28+ return page ;
29+ }
30+ if ( page . children ) {
31+ let result = findSelfInNavPages ( page . children , url ) ;
32+ if ( result ) return result ;
33+ }
34+ }
35+
36+ return null ;
37+ }
38+
2339module . exports = function ( eleventyConfig ) {
2440 eleventyConfig . addPlugin ( EleventyRenderPlugin ) ;
2541 eleventyConfig . addPlugin ( eleventyNavigationPlugin ) ;
@@ -39,7 +55,7 @@ module.exports = function (eleventyConfig) {
3955 return `<script type="module" src="${ filepath . replace ( 'src' , '' ) } "></script>` ;
4056 }
4157
42- console . log ( `Script file ${ filename } .js not found in /src/static/js/` ) ;
58+ console . log ( `script file ${ filename } .js not found in /src/static/js/` ) ;
4359 return '' ;
4460 } ) ;
4561
@@ -49,7 +65,7 @@ module.exports = function (eleventyConfig) {
4965 return `<link rel="stylesheet" href="${ filepath . replace ( 'src' , '' ) . replace ( '.sass' , '.css' ) } ">` ;
5066 }
5167
52- console . log ( `Style file ${ filename } .sass not found in /src/static/css/` ) ;
68+ console . log ( `style file ${ filename } .sass not found in /src/static/css/` ) ;
5369 return '' ;
5470 } ) ;
5571
@@ -62,7 +78,32 @@ module.exports = function (eleventyConfig) {
6278 let version = json . version ;
6379 let channel = json . channel && json . channel !== 'RTW' ? ` (${ json . channel } )` : '' ;
6480 let versionString = `${ version } ${ channel } ` ;
65- return `<a id="version-tag" href="https://github.com/miermontoto/miermontoto/commit/${ json . channel === "RTW" ? 'main' : 'beta' } " target="_blank">${ versionString } </span>` ;
81+ return `<a id="version-tag" href="https://github.com/miermontoto/miermontoto/commit/${ json . channel === "RTW" ? 'main' : 'beta' } " target="_blank">${ versionString } </a>` ;
82+ } ) ;
83+
84+ eleventyConfig . addShortcode ( "breadcrumbs" , function ( navPages ) {
85+ if ( ! this . page . url ) return '' ; // if permalink is false in frontmatter, don't show breadcrumbs
86+ let targetName = this . page . url . replace ( '/' , '' ) . replace ( '/' , '' ) . replace ( '.html' , '' ) . toLowerCase ( ) ;
87+ let beta = this . page . url . replace ( '.html' , '' ) . split ( '/' ) ;
88+ beta . shift ( ) ;
89+ beta = beta . join ( '/' ) ;
90+ if ( beta . endsWith ( '/' ) ) beta = beta . slice ( 0 , - 1 ) ;
91+ console . log ( `targetName: ${ beta } ` ) ;
92+ let currentPage = findSelfInNavPages ( navPages , targetName ) ;
93+ if ( ! currentPage ) {
94+ console . log ( `unable to produce breadcrumbs for ${ targetName } .` ) ;
95+ return '' ;
96+ }
97+ let html = `<nav aria-label="breadcrumbs" id="breadcrumbs">$ <a href="/">/</a>` ;
98+
99+
100+ if ( currentPage . parent ) {
101+ let parentPage = findSelfInNavPages ( navPages , currentPage . parent ) ;
102+ html += `<span class="bc-spacer"> > </span><a class="bc-target" href="${ parentPage . url } ">${ parentPage . key } </a>` ;
103+ }
104+ html += `<span class="bc-spacer"> > </span><b class="bc-target">${ currentPage . title || currentPage . key } </b>` ;
105+ html += `</nav>` ;
106+ return html ;
66107 } ) ;
67108
68109 eleventyConfig . addShortcode ( "top" , function ( ) {
@@ -122,7 +163,7 @@ module.exports = function (eleventyConfig) {
122163 template += '</div>' ;
123164 if ( exam || ! shuffle ) {
124165 template += `<ul class="asterisks">
125- ${ exam ? '<li class="exam">pregunta de examen reciente</span >' : '' }
166+ ${ exam ? '<li class="exam">pregunta de examen reciente</li >' : '' }
126167 ${ ! shuffle ? '<li class="shuffle">orden de respuestas fijado</li>' : '' }
127168 </ul>` ;
128169 }
@@ -134,6 +175,16 @@ module.exports = function (eleventyConfig) {
134175 return template ;
135176 } ) ;
136177
178+ const nunjucksEnvironment = new Nunjucks . Environment (
179+ new Nunjucks . FileSystemLoader ( "./" ) ,
180+ {
181+ lstripBlocks : true ,
182+ trimBlocks : true
183+ }
184+ ) ;
185+
186+ eleventyConfig . setLibrary ( "njk" , nunjucksEnvironment ) ;
187+
137188 return {
138189 dir : {
139190 input : "src" ,
0 commit comments