Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit a110eddc authored by Pierre Jarriges's avatar Pierre Jarriges
Browse files

feat: support build subpages

parent 75f1c4d0
No related branches found
No related tags found
No related merge requests found
...@@ -87,9 +87,8 @@ function getPageHtml(pageName, pageMeta) { ...@@ -87,9 +87,8 @@ function getPageHtml(pageName, pageMeta) {
defaultValue: (function () { defaultValue: (function () {
const urlContent = getDefaultOgMetaContent("url"); const urlContent = getDefaultOgMetaContent("url");
return `${urlContent}${ return `${urlContent}${urlContent.charAt(urlContent.length - 1) !== "/" ? "/" : ""
urlContent.charAt(urlContent.length - 1) !== "/" ? "/" : "" }${pageName}`;
}${pageName}`;
})(), })(),
}, },
{ {
...@@ -110,8 +109,8 @@ function getPageHtml(pageName, pageMeta) { ...@@ -110,8 +109,8 @@ function getPageHtml(pageName, pageMeta) {
else { else {
return Array.isArray(customValue) return Array.isArray(customValue)
? customValue ? customValue
.map(alt => `<meta property="og:${key}" content="${alt}"/>`) .map(alt => `<meta property="og:${key}" content="${alt}"/>`)
.join("\n") .join("\n")
: `<meta property="og:${key}" content="${customValue}"/>`; : `<meta property="og:${key}" content="${customValue}"/>`;
} }
})() })()
...@@ -151,13 +150,12 @@ function getPageHtml(pageName, pageMeta) { ...@@ -151,13 +150,12 @@ function getPageHtml(pageName, pageMeta) {
// set twitter image // set twitter image
html = html.replace( html = html.replace(
html.match(new RegExp(`<meta\\s*property="twitter:image"[^>]+>`, "g"))[0], html.match(new RegExp(`<meta\\s*property="twitter:image"[^>]+>`, "g"))[0],
`<meta property="twitter:image" content="${ `<meta property="twitter:image" content="${pageMeta.image ||
pageMeta.image || html
html .match(new RegExp(`<meta\\s*name="image"[^>]+>`, "g"))[0]
.match(new RegExp(`<meta\\s*name="image"[^>]+>`, "g"))[0] .match(new RegExp(`content=".+"`, "g"))[0]
.match(new RegExp(`content=".+"`, "g"))[0] .match(new RegExp(`".+"`, "g"))
.match(new RegExp(`".+"`, "g")) .replace(/"/g, "")
.replace(/"/g, "")
}"/>` }"/>`
); );
...@@ -165,43 +163,92 @@ function getPageHtml(pageName, pageMeta) { ...@@ -165,43 +163,92 @@ function getPageHtml(pageName, pageMeta) {
return html; return html;
} }
const pages = fs.readdirSync(`${curDir}/src/pages`); function createPages(rootdir, destdir) {
const pages = fs.readdirSync(rootdir);
for (const p of pages) { for (const p of pages) {
const fPath = `${curDir}/src/pages/${p}`; const fPath = `${rootdir}/${p}`;
const targetDirPath = `${curDir}/public/${p}`; const targetDirPath = `${destdir}/${p}`;
if (!fs.existsSync(targetDirPath)) { if (!fs.existsSync(targetDirPath)) {
fs.mkdirSync(targetDirPath); fs.mkdirSync(targetDirPath);
} }
const b = browserify(); const b = browserify();
b.add(fPath) b.add(fPath)
.bundle() .bundle()
.pipe(fs.createWriteStream(`${targetDirPath}/${p}.js`)); .pipe(fs.createWriteStream(`${targetDirPath}/${p}.js`));
const page = fs.createWriteStream(`${targetDirPath}/index.html`); const page = fs.createWriteStream(`${targetDirPath}/index.html`);
const pageMeta = JSON.parse(fs.readFileSync(`${fPath}/meta.json`, "utf-8")); const pageMeta = JSON.parse(fs.readFileSync(`${fPath}/meta.json`, "utf-8"));
page.write(getPageHtml(p, pageMeta)); page.write(getPageHtml(p, pageMeta));
}
// If pages have been deleted in source, remove them in output directory too. if (fs.existsSync(`${fPath}/subpages`)) {
for (const dir of fs.readdirSync(`${curDir}/public`).filter(f => { createPages(`${fPath}/subpages`, targetDirPath)
if (build_conf.protected_dirs.includes(f)) return false; }
const stats = fs.statSync(`${curDir}/public/${f}`); }
return stats.isDirectory();
})) { // If pages have been deleted in source, remove them in output directory too.
if (!pages.includes(dir)) { for (const dir of fs.readdirSync(destdir).filter(f => {
const dPath = `${curDir}/public/${dir}`; if (build_conf.protected_dirs.includes(f)) return false;
try { const stats = fs.statSync(`${destdir}/${f}`);
const nestedFiles = fs.readdirSync(dPath); return stats.isDirectory();
for (const nf of nestedFiles) { })) {
fs.unlinkSync(`${dPath}/${nf}`); if (!pages.includes(dir)) {
const dPath = `${destdir}/${dir}`;
try {
const nestedFiles = fs.readdirSync(dPath);
for (const nf of nestedFiles) {
fs.unlinkSync(`${dPath}/${nf}`);
}
fs.rmdirSync(dPath);
} catch (error) {
console.error(error);
} }
fs.rmdirSync(dPath);
} catch (error) {
console.error(error);
} }
} }
} }
createPages(`${curDir}/src/pages`, `${curDir}/public`);
// const pages = fs.readdirSync(`${curDir}/src/pages`);
// for (const p of pages) {
// const fPath = `${curDir}/src/pages/${p}`;
// const targetDirPath = `${curDir}/public/${p}`;
// if (!fs.existsSync(targetDirPath)) {
// fs.mkdirSync(targetDirPath);
// }
// const b = browserify();
// b.add(fPath)
// .bundle()
// .pipe(fs.createWriteStream(`${targetDirPath}/${p}.js`));
// const page = fs.createWriteStream(`${targetDirPath}/index.html`);
// const pageMeta = JSON.parse(fs.readFileSync(`${fPath}/meta.json`, "utf-8"));
// page.write(getPageHtml(p, pageMeta));
// }
// // If pages have been deleted in source, remove them in output directory too.
// for (const dir of fs.readdirSync(`${curDir}/public`).filter(f => {
// if (build_conf.protected_dirs.includes(f)) return false;
// const stats = fs.statSync(`${curDir}/public/${f}`);
// return stats.isDirectory();
// })) {
// if (!pages.includes(dir)) {
// const dPath = `${curDir}/public/${dir}`;
// try {
// const nestedFiles = fs.readdirSync(dPath);
// for (const nf of nestedFiles) {
// fs.unlinkSync(`${dPath}/${nf}`);
// }
// fs.rmdirSync(dPath);
// } catch (error) {
// console.error(error);
// }
// }
// }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment