fix: transform links with basepath

This commit is contained in:
2025-02-07 16:52:17 +01:00
parent 3a00e7c680
commit a5fe0a7054
5 changed files with 36 additions and 6 deletions

View File

@@ -5,6 +5,7 @@ import layouts from '@metalsmith/layouts'
import markdown from '@metalsmith/markdown'
import permalinks from '@metalsmith/permalinks'
import collections from '@metalsmith/collections'
import inPlace from '@metalsmith/in-place'
const __dirname = dirname(fileURLToPath(import.meta.url))
const t1 = performance.now()
@@ -36,14 +37,26 @@ Metalsmith(__dirname)
TZ: 'Europe/Paris',
})
.metadata(sitedata)
.use(inPlace({
pattern: '**/*.md',
transform: 'handlebars'
}))
.use(markdown())
.use(permalinks())
.use(collections({
nav: {
pattern: '**/*.html',
sortBy: 'nav_order'
sortBy: 'nav_order',
metadata: {
base: sitedata.site.basePath
}
}
}))
.use(permalinks())
.use(function addBasePathToCollection(files) {
Object.values(files).forEach(file => {
file.basePath = sitedata.site.basePath;
});
})
.use(layouts({
directory: 'layouts',
default: 'default.hbs',

View File

@@ -25,7 +25,7 @@
<img src="{{ site.basePath }}/assets/images/brand.jpg" alt="Logo du {{ site.subject }}" />
<nav>
{{#each collections.nav}}
<a href="{{ this.path }}">{{ this.title }}</a>
<a href="{{ basePath }}/{{ path }}">{{ title }}</a>
{{/each}}
</nav>
<button id="theme-toggle" class="theme-toggle">🌙</button>
@@ -75,8 +75,8 @@
</div>
</footer>
<script src="{{ site.basePath }}/assets/scripts/theme-toggle.js" async defer ></script>
<script src="{{ site.basePath }}/assets/scripts/page-size.js" async defer ></script>
<script async src="{{ site.basePath }}/assets/scripts/theme-toggle.js" ></script>
<script src="{{ site.basePath }}/assets/scripts/page-size.js" ></script>
</body>
</html>

16
package-lock.json generated
View File

@@ -7,6 +7,7 @@
"name": "ltg-grenoble",
"dependencies": {
"@metalsmith/collections": "^1.3.1",
"@metalsmith/in-place": "^5.0.0",
"@metalsmith/layouts": "^2.7.0",
"@metalsmith/markdown": "^1.10.0",
"@metalsmith/permalinks": "^3.2.0",
@@ -32,6 +33,21 @@
"metalsmith": "^2.5.0"
}
},
"node_modules/@metalsmith/in-place": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/@metalsmith/in-place/-/in-place-5.0.0.tgz",
"integrity": "sha512-7b7w4OPm5yvBysEVbFcEsEtrToEhcN8gv9+MJTmvu3SPVnflJ9i8W4MfZfG71hIi8hvKEqQFGdKgAzhcX8d1zQ==",
"dependencies": {
"is-utf8": "^0.2.1",
"jstransformer": "^1.0.0"
},
"engines": {
"node": ">=14.14.0"
},
"peerDependencies": {
"metalsmith": "^2.5.0"
}
},
"node_modules/@metalsmith/layouts": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/@metalsmith/layouts/-/layouts-2.7.0.tgz",

View File

@@ -8,6 +8,7 @@
},
"dependencies": {
"@metalsmith/collections": "^1.3.1",
"@metalsmith/in-place": "^5.0.0",
"@metalsmith/layouts": "^2.7.0",
"@metalsmith/markdown": "^1.10.0",
"@metalsmith/permalinks": "^3.2.0",