1
0
forked from ti-nuage/site

Mise en évidence automatique des liens externes.

Ceci concerne uniquement le traitement des fichiers Markdown (il est
toujours nécessaire de traiter manuellement les sources écrites en
HTML).

Pour réaliser cette fonction, le plugin metalsmith-mardownit a été
remplacé par @metalsmith/markdown.
This commit is contained in:
David Soulayrol
2022-09-04 09:54:31 +02:00
parent 1f8be84377
commit ddde4f1309
3 changed files with 121 additions and 131 deletions

View File

@@ -7,7 +7,8 @@ const excerpts = require('@metalsmith/excerpts')
const groff = require('metalsmith-groff')
const layouts = require('@metalsmith/layouts')
const Metalsmith = require('metalsmith')
const markdown = require('metalsmith-markdownit')
const markdown = require('@metalsmith/markdown')
const marked = require('marked')
const moment = require('moment')
const permalinks = require('@metalsmith/permalinks')
const rename = require('metalsmith-rename')
@@ -17,6 +18,20 @@ const statistics = require('./metalsmith-statistics-plugin')
const __PROD__ = process.env.NODE_ENV === 'production'
const markdownRenderer = new marked.Renderer()
const m = markdownRenderer.link
markdownRenderer.link = function (href, title, text) {
let out = m.apply(this, [href, title, text])
if (href.startsWith('http') && !href.match('^https?://(www.)?ti-nuage\\.fr/.*')) {
out = out.slice(0, 3) + ' class="external" ' + out.slice(3)
}
return out
}
moment.locale('fr')
module.exports = new Metalsmith(config.paths.projectRoot)
@@ -43,14 +58,11 @@ module.exports = new Metalsmith(config.paths.projectRoot)
}))
.use(groff())
.use(markdown({
html: true,
linkify: true,
typographer: true,
quotes: ['«\xA0', '\xA0»', '\xA0', '\xA0'],
plugin: {
pattern: '**/*.md',
extension: 'html'
}
gfm: false,
headerIds: false,
renderer: markdownRenderer,
smartypants: true,
xhtml: true
}))
.use(excerpts())
.use(permalinks({