34 lines
944 B
JavaScript
34 lines
944 B
JavaScript
|
'use strict';
|
||
|
|
||
|
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);
|
||
|
})
|