38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
import {fromHtml} from 'hast-util-from-html';
|
|
import {toHtml} from 'hast-util-to-html';
|
|
import {visit} from 'unist-util-visit';
|
|
/*
|
|
* The idea: need to create another subdir `title/nl/index.html`
|
|
*/
|
|
|
|
export default async (page) => {
|
|
const html = await page.html;
|
|
return {
|
|
"index.html": page.html,
|
|
...handleTranslations(html, page.trls)
|
|
}
|
|
}
|
|
|
|
function handleTranslations(html, trls) {
|
|
if (trls) {
|
|
const outputs = {};
|
|
trls.forEach(trl => {
|
|
outputs[trl] = {
|
|
"index.html": reorderTranslations(html, trl)
|
|
}
|
|
})
|
|
return outputs;
|
|
} else {
|
|
return;
|
|
}
|
|
}
|
|
|
|
//reorders all '.translation-group's so the element with given lang is first, and 'open' is set appropriately.
|
|
//also, handles latest/laatst. Is that a special case, or should that be translated in the page too?
|
|
function reorderTranslations(body, lang){
|
|
//handles both text and dom object as input
|
|
const hast = fromHtml(body);
|
|
//visit: trlselector>radio, and set active on current lang and inactive on other langs.
|
|
return toHtml(hast);
|
|
}
|