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) {
defaultValue: (function () {
const urlContent = getDefaultOgMetaContent("url");
return `${urlContent}${
urlContent.charAt(urlContent.length - 1) !== "/" ? "/" : ""
}${pageName}`;
return `${urlContent}${urlContent.charAt(urlContent.length - 1) !== "/" ? "/" : ""
}${pageName}`;
})(),
},
{
......@@ -110,8 +109,8 @@ function getPageHtml(pageName, pageMeta) {
else {
return Array.isArray(customValue)
? customValue
.map(alt => `<meta property="og:${key}" content="${alt}"/>`)
.join("\n")
.map(alt => `<meta property="og:${key}" content="${alt}"/>`)
.join("\n")
: `<meta property="og:${key}" content="${customValue}"/>`;
}
})()
......@@ -151,13 +150,12 @@ function getPageHtml(pageName, pageMeta) {
// set twitter image
html = html.replace(
html.match(new RegExp(`<meta\\s*property="twitter:image"[^>]+>`, "g"))[0],
`<meta property="twitter:image" content="${
pageMeta.image ||
html
.match(new RegExp(`<meta\\s*name="image"[^>]+>`, "g"))[0]
.match(new RegExp(`content=".+"`, "g"))[0]
.match(new RegExp(`".+"`, "g"))
.replace(/"/g, "")
`<meta property="twitter:image" content="${pageMeta.image ||
html
.match(new RegExp(`<meta\\s*name="image"[^>]+>`, "g"))[0]
.match(new RegExp(`content=".+"`, "g"))[0]
.match(new RegExp(`".+"`, "g"))
.replace(/"/g, "")
}"/>`
);
......@@ -165,43 +163,92 @@ function getPageHtml(pageName, pageMeta) {
return html;
}
const pages = fs.readdirSync(`${curDir}/src/pages`);
function createPages(rootdir, destdir) {
const pages = fs.readdirSync(rootdir);
for (const p of pages) {
const fPath = `${curDir}/src/pages/${p}`;
const targetDirPath = `${curDir}/public/${p}`;
for (const p of pages) {
const fPath = `${rootdir}/${p}`;
const targetDirPath = `${destdir}/${p}`;
if (!fs.existsSync(targetDirPath)) {
fs.mkdirSync(targetDirPath);
}
if (!fs.existsSync(targetDirPath)) {
fs.mkdirSync(targetDirPath);
}
const b = browserify();
const b = browserify();
b.add(fPath)
.bundle()
.pipe(fs.createWriteStream(`${targetDirPath}/${p}.js`));
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));
}
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}`);
if (fs.existsSync(`${fPath}/subpages`)) {
createPages(`${fPath}/subpages`, targetDirPath)
}
}
// If pages have been deleted in source, remove them in output directory too.
for (const dir of fs.readdirSync(destdir).filter(f => {
if (build_conf.protected_dirs.includes(f)) return false;
const stats = fs.statSync(`${destdir}/${f}`);
return stats.isDirectory();
})) {
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