2019-09-07 09:53:11 +03:00
|
|
|
module.exports = function pagesInit({ mainElmModule }) {
|
2019-08-15 03:42:02 +03:00
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
|
|
let app = mainElmModule.init({
|
2019-09-07 09:53:11 +03:00
|
|
|
flags: {}
|
2019-08-15 03:42:02 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
app.ports.toJsPort.subscribe(headTags => {
|
|
|
|
if (navigator.userAgent.indexOf("Headless") >= 0) {
|
|
|
|
headTags.forEach(headTag => {
|
|
|
|
appendTag(headTag);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
document.dispatchEvent(new Event("prerender-trigger"));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function appendTag(tagDetails) {
|
|
|
|
const meta = document.createElement(tagDetails.name);
|
|
|
|
tagDetails.attributes.forEach(([name, value]) => {
|
|
|
|
meta.setAttribute(name, value);
|
|
|
|
});
|
|
|
|
document.getElementsByTagName("head")[0].appendChild(meta);
|
|
|
|
}
|
|
|
|
};
|