hugo-theme-lowtech/scripts/typo.js

36 lines
1010 B
JavaScript

'use strict';
// https://crowdagger.github.io/textes/articles/heuristique.html
const path = require('path');
const { loadPages, savePages } = require('./page');
const richtypo = require('richtypo');
const frRules = require('richtypo-rules-fr');
const { definitions } = require('richtypo-rules-common');
console.log('Prepares your texts to publication on web: applies typography rules.');
const openingQuote = '« ';
const closingQuote = ' »';
const quotes = text => text
.replace(
new RegExp(`${definitions.notInTag}(["“«]|“)((${definitions.tag})?(${definitions.dash}${definitions.space})?${definitions.letter})`, 'gmi'),
`${openingQuote}$2`
)
.replace(
new RegExp(`${definitions.notInTag}(["”»]|”)`, 'gmi'),
`${closingQuote}`
);
const rt = richtypo.default([frRules.default, quotes]);
const folder = path.resolve(process.cwd(), 'public')
loadPages(folder).then(pages => {
for (const page of pages) {
page.content = rt(page.content)
}
savePages(pages);
})