From fb051b08f3e6825b582d3750b1ab631f86e458d7 Mon Sep 17 00:00:00 2001 From: peter_rabbit <pierrejarriges@gmail.com> Date: Thu, 28 Jan 2021 10:01:47 +0100 Subject: [PATCH] build from html template --- build.js | 51 ++++++++++++------- public/education/education.js | 6 +++ public/education/index.html | 5 +- public/games/games.js | 6 +++ public/games/index.html | 5 +- public/index.html | 1 + public/software-development/index.html | 5 +- .../software-development.js | 6 +++ src/lib/web-page.js | 6 +++ src/pages/education/meta.json | 4 ++ src/pages/games/meta.json | 4 ++ src/pages/software-development/meta.json | 4 ++ 12 files changed, 76 insertions(+), 27 deletions(-) create mode 100644 src/pages/education/meta.json create mode 100644 src/pages/games/meta.json create mode 100644 src/pages/software-development/meta.json diff --git a/build.js b/build.js index f0b0f8b..6bdbd9a 100644 --- a/build.js +++ b/build.js @@ -17,23 +17,37 @@ b.add(`${curDir}/src/main.js`) .pipe(fs.createWriteStream(`${curDir}/public/main.js`)); // Handle subpages -function getPageHtml(pagename) { - return ` -<!DOCTYPE html> -<html lang="fr"> - <head> - <meta charset="utf-8" /> - <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> - <title>Kuadrado Software - ${pagename}</title> - <link rel="icon" type="image/svg+xml" href="/favicon.svg"> - <link href="/style/style.css" rel="stylesheet" /> - </head> - <body> - <main></main> - </body> - <script type="text/javascript" src="./${pagename}.js"></script> -</html> - `; +function getPageHtml(pageName, pageMeta) { + let html = fs.readFileSync(`${curDir}/public/index.html`, "utf-8"); + const setMeta = function (metaName, value) { + return html.replace( + html.match(new RegExp(`<meta.+name="${metaName}".+>`, "g")), + `<meta name="${metaName}" content="${value}">` + ); + }; + const setTitle = function (value) { + return html.replace( + html.match(new RegExp(`<title.+</title>`, "g")), + `<title>${value}</title>` + ); + }; + const setStyleSheet = function () { + return html.replace( + html.match(new RegExp(`<link.+/style.css>`, "g")), + `<link href="/style/style.css" rel="stylesheet" />` + ); + }; + const setJs = function () { + return html.replace( + html.match(new RegExp(`<script.+main.js.+</script>`, "g")), + `<script type="text/javascript" src="./${pageName}.js"></script>` + ); + }; + html = setMeta("description", pageMeta.description); + html = setTitle(pageMeta.title); + html = setStyleSheet(); + html = setJs(); + return html; } const pages = fs.readdirSync(`${curDir}/src/pages`); @@ -53,7 +67,8 @@ for (const p of pages) { .pipe(fs.createWriteStream(`${targetDirPath}/${p}.js`)); const page = fs.createWriteStream(`${targetDirPath}/index.html`); - page.write(getPageHtml(p)); + 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. diff --git a/public/education/education.js b/public/education/education.js index d576f8b..60c301a 100644 --- a/public/education/education.js +++ b/public/education/education.js @@ -111,6 +111,12 @@ class WebPage { constructor(args) { Object.assign(this, args); } + + // setMeta() { + // if (!this.meta) { + // console.warn("Meta information missing") + // } + // } } module.exports = WebPage; diff --git a/public/education/index.html b/public/education/index.html index 04962dd..23ca440 100644 --- a/public/education/index.html +++ b/public/education/index.html @@ -1,10 +1,10 @@ - <!DOCTYPE html> <html lang="fr"> <head> <meta charset="utf-8" /> + <title>Kuadrado Software | Pédagogie</title> + <meta name="description" content="Animations autour de la création de jeux vidéos, vulgarisation numérique. Découvrez nos initiatives pédagogiques."> <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> - <title>Kuadrado Software - education</title> <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <link href="/style/style.css" rel="stylesheet" /> </head> @@ -13,4 +13,3 @@ </body> <script type="text/javascript" src="./education.js"></script> </html> - \ No newline at end of file diff --git a/public/games/games.js b/public/games/games.js index 9f8e5ed..f8474eb 100644 --- a/public/games/games.js +++ b/public/games/games.js @@ -269,6 +269,12 @@ class WebPage { constructor(args) { Object.assign(this, args); } + + // setMeta() { + // if (!this.meta) { + // console.warn("Meta information missing") + // } + // } } module.exports = WebPage; diff --git a/public/games/index.html b/public/games/index.html index 820f92c..e68f86f 100644 --- a/public/games/index.html +++ b/public/games/index.html @@ -1,10 +1,10 @@ - <!DOCTYPE html> <html lang="fr"> <head> <meta charset="utf-8" /> + <title>Kuadrado Software | Jeux</title> + <meta name="description" content="Création de jeux vidéos indépendants. Jeux web, PC et projets en cours de développement"> <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> - <title>Kuadrado Software - games</title> <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <link href="/style/style.css" rel="stylesheet" /> </head> @@ -13,4 +13,3 @@ </body> <script type="text/javascript" src="./games.js"></script> </html> - \ No newline at end of file diff --git a/public/index.html b/public/index.html index a4e2bc3..2edf934 100644 --- a/public/index.html +++ b/public/index.html @@ -3,6 +3,7 @@ <head> <meta charset="utf-8" /> <title>Kuadrado Software</title> + <meta name="description" content="Créations numériques, jeux vidéos, web, software et pédagogie."> <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <link href="/style/style.css" rel="stylesheet" /> diff --git a/public/software-development/index.html b/public/software-development/index.html index c66f21a..431e009 100644 --- a/public/software-development/index.html +++ b/public/software-development/index.html @@ -1,10 +1,10 @@ - <!DOCTYPE html> <html lang="fr"> <head> <meta charset="utf-8" /> + <title>Kuadrado Software | Software</title> + <meta name="description" content="Développement web, moteur de jeux, outillage logiciel, retrouvez nos projets en détail."> <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> - <title>Kuadrado Software - software-development</title> <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <link href="/style/style.css" rel="stylesheet" /> </head> @@ -13,4 +13,3 @@ </body> <script type="text/javascript" src="./software-development.js"></script> </html> - \ No newline at end of file diff --git a/public/software-development/software-development.js b/public/software-development/software-development.js index f8c40d4..68e82f3 100644 --- a/public/software-development/software-development.js +++ b/public/software-development/software-development.js @@ -269,6 +269,12 @@ class WebPage { constructor(args) { Object.assign(this, args); } + + // setMeta() { + // if (!this.meta) { + // console.warn("Meta information missing") + // } + // } } module.exports = WebPage; diff --git a/src/lib/web-page.js b/src/lib/web-page.js index b58f4c0..022fd3b 100644 --- a/src/lib/web-page.js +++ b/src/lib/web-page.js @@ -4,6 +4,12 @@ class WebPage { constructor(args) { Object.assign(this, args); } + + // setMeta() { + // if (!this.meta) { + // console.warn("Meta information missing") + // } + // } } module.exports = WebPage; \ No newline at end of file diff --git a/src/pages/education/meta.json b/src/pages/education/meta.json new file mode 100644 index 0000000..3f229c5 --- /dev/null +++ b/src/pages/education/meta.json @@ -0,0 +1,4 @@ +{ + "title": "Kuadrado Software | Pédagogie", + "description": "Animations autour de la création de jeux vidéos, vulgarisation numérique. Découvrez nos initiatives pédagogiques." +} \ No newline at end of file diff --git a/src/pages/games/meta.json b/src/pages/games/meta.json new file mode 100644 index 0000000..7476b5c --- /dev/null +++ b/src/pages/games/meta.json @@ -0,0 +1,4 @@ +{ + "title": "Kuadrado Software | Jeux", + "description": "Création de jeux vidéos indépendants. Jeux web, PC et projets en cours de développement" +} \ No newline at end of file diff --git a/src/pages/software-development/meta.json b/src/pages/software-development/meta.json new file mode 100644 index 0000000..b6f4d51 --- /dev/null +++ b/src/pages/software-development/meta.json @@ -0,0 +1,4 @@ +{ + "title": "Kuadrado Software | Software", + "description": "Développement web, moteur de jeux, outillage logiciel, retrouvez nos projets en détail." +} \ No newline at end of file -- GitLab