diff --git a/build.js b/build.js index cda3ae56ac215fcf2f789c0f3077824ebd52f365..15d298cc5217a073ab8117812fa21fd909a8f555 100644 --- a/build.js +++ b/build.js @@ -2,13 +2,12 @@ "use strict"; -const build_conf = { - protected_dirs: ["assets", "style", "articles"], -}; const fs = require("fs"); const browserify = require("browserify"); +const config = require("./config"); const curDir = process.cwd(); +const build_conf = config.build; // Handle home page const b = browserify(); @@ -20,31 +19,31 @@ b.add(`${curDir}/src/main.js`) 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")), + html = html.replace( + html.match(new RegExp(`<meta\\s*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 setTitle = function () { + html = html.replace( + html.match(new RegExp(`<title.+</title>`, "g"))[0], + `<title>${pageMeta.title}</title>` ); }; const setStyleSheet = function () { - return html.replace( - html.match(new RegExp(`<link.+/style.css>`, "g")), + html = html.replace( + html.match(new RegExp(`<link.+/style.css[^>]+>`, "g"))[0], `<link href="/style/style.css" rel="stylesheet" />` ); }; const setJs = function () { - return html.replace( - html.match(new RegExp(`<script.+main.js.+</script>`, "g")), + html = html.replace( + html.match(new RegExp(`<script.+main.js.+</script>`, "g"))[0], `<script type="text/javascript" src="./${pageName}.js"></script>` ); }; const setAdditionalMeta = function (metas) { - return html.replace( + html = html.replace( "</head>", `${metas .map(kv => { @@ -54,14 +53,69 @@ function getPageHtml(pageName, pageMeta) { .join("\n")}</head>` ); }; - html = setMeta("description", pageMeta.description); - html = setTitle(pageMeta.title); - html = setStyleSheet(); - html = setJs(); - html = setAdditionalMeta( - Object.entries(pageMeta).filter(kv => kv[0] !== "description" && kv[0] !== "title") - ); + const setOgMeta = function () { + const pageOgMeta = pageMeta.open_graph || {}; + + const getOgMetaSearchRegex = function (name) { + return new RegExp(`<meta\\s*property="og:${name}"[^>]+>`, "g"); + }; + const getDefaultOgMetaContent = function (name) { + const getRegexMatch = function (source, searchRe) { + const m = source.match(searchRe); + return m ? m[0] : ""; + }; + return getRegexMatch( + getRegexMatch( + getRegexMatch(html, getOgMetaSearchRegex(name)), + new RegExp(`content=".+"`, "g") + ), + new RegExp(`".+"`, "g") + ).replace(/"/g, ""); + }; + const requiredOgMeta = [ + { key: "title", defaultValue: pageMeta.title }, + { key: "description", defaultValue: pageMeta.description }, + { + key: "image", + defaultValue: getDefaultOgMetaContent("image"), + }, + { + key: "url", + defaultValue: (function () { + const urlContent = getDefaultOgMetaContent("url"); + + return `${urlContent}${ + urlContent.charAt(urlContent.length - 1) !== "/" ? "/" : "" + }${pageName}`; + })(), + }, + { + key: "locale", + defaultValue: getDefaultOgMetaContent("locale"), + }, + // TODO : handle locale:alternate meta tags array + ]; + requiredOgMeta.forEach(entry => { + const { key, defaultValue } = entry; + html = html.replace( + html.match(getOgMetaSearchRegex(key)), + `<meta property="og:${key}" content="${pageOgMeta[key] || defaultValue}" />` + ); + }); + + // TODO handle addition og meta + }; + setMeta("description", pageMeta.description); + setTitle(); + setStyleSheet(); + setJs(); + setAdditionalMeta( + Object.entries(pageMeta).filter( + kv => !build_conf.default_meta_keys.includes(kv[0]) + ) + ); + setOgMeta(); return html; } diff --git a/config.js b/config.js index 5b5dc12c10a3c2ce0e72e4cb549d68d6cdf41f2f..30b3683c7c0cfe8fd71c2855e0ce947f74b49ffe 100644 --- a/config.js +++ b/config.js @@ -7,4 +7,8 @@ function getServerUrl() { module.exports = { getServerUrl, website_title: "Kuadrado website template", + build: { + protected_dirs: ["assets", "style", "articles"], + default_meta_keys: ["title", "description", "open_graph"], + }, }; diff --git a/public/education/education.js b/public/education/education.js index 49c26e69192a9bcbbfde5c07588f06ffb9f1c99b..49c9160a3eefc25a611e875db0287b9a2788956e 100644 --- a/public/education/education.js +++ b/public/education/education.js @@ -8,6 +8,10 @@ function getServerUrl() { module.exports = { getServerUrl, website_title: "Kuadrado website template", + build: { + protected_dirs: ["assets", "style", "articles"], + default_meta_keys: ["title", "description", "open_graph"], + }, }; },{}],2:[function(require,module,exports){ diff --git a/public/education/index.html b/public/education/index.html index 51e755d5417028a4626333480957198d75d3c796..660916db0a66ac811e709050940b13057055e47f 100644 --- a/public/education/index.html +++ b/public/education/index.html @@ -1,11 +1,24 @@ <!DOCTYPE html> -<html lang="fr"> +<html lang="fr" prefix="og: https://ogp.me/ns#"> <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."/> + + <!-- Open Graph Protocol meta data --> + <meta property="og:title" content="Kuadrado Software | Pédagogie" /> + <meta property="og:description" content="Animations autour de la création de jeux vidéos, vulgarisation numérique. Découvrez nos initiatives pédagogiques." /> + <meta property="og:type" content="website" /> + <meta property="og:url" content="https://kuadrado-software.fr/education" /> + <meta property="og:image" content="https://kuadrado-software.fr/assets/images/brain.svg" /> + <meta property="og:locale" content="fr_FR" /> + + <!-- English translation not ready yet --> + <!-- <meta property="og:locale:alternate" content="en_GB" /> --> + <!-- END OGP --> + <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> - <link rel="icon" type="image/svg+xml" href="/favicon.svg"> + <link rel="icon" type="image/svg+xml" href="/favicon.svg" /> <link href="/style/style.css" rel="stylesheet" /> </head> <body> diff --git a/public/games/games.js b/public/games/games.js index d566c7acabc04b68eed84aed90b506d6b0a048ad..e516a666a5697aba8be4500168ea40ff8e6cdaae 100644 --- a/public/games/games.js +++ b/public/games/games.js @@ -8,6 +8,10 @@ function getServerUrl() { module.exports = { getServerUrl, website_title: "Kuadrado website template", + build: { + protected_dirs: ["assets", "style", "articles"], + default_meta_keys: ["title", "description", "open_graph"], + }, }; },{}],2:[function(require,module,exports){ diff --git a/public/games/index.html b/public/games/index.html index 5fbf110cf908957e8fe2678af6573187595ae8fb..eb16d90df4b2b05bf4d1ba0c26c8895efa38a232 100644 --- a/public/games/index.html +++ b/public/games/index.html @@ -1,11 +1,24 @@ <!DOCTYPE html> -<html lang="fr"> +<html lang="fr" prefix="og: https://ogp.me/ns#"> <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"/> + + <!-- Open Graph Protocol meta data --> + <meta property="og:title" content="Kuadrado Software | Jeux" /> + <meta property="og:description" content="Création de jeux vidéos indépendants. Jeux web, PC et projets en cours de développement" /> + <meta property="og:type" content="website" /> + <meta property="og:url" content="https://kuadrado-software.fr/games" /> + <meta property="og:image" content="https://kuadrado-software.fr/assets/images/game_controller.svg" /> + <meta property="og:locale" content="fr_FR" /> + + <!-- English translation not ready yet --> + <!-- <meta property="og:locale:alternate" content="en_GB" /> --> + <!-- END OGP --> + <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> - <link rel="icon" type="image/svg+xml" href="/favicon.svg"> + <link rel="icon" type="image/svg+xml" href="/favicon.svg" /> <link href="/style/style.css" rel="stylesheet" /> </head> <body> diff --git a/public/index.html b/public/index.html index 2edf9345588a0464e3c6edd236b128a39ee22cc6..76d6135a6db33aacd96a973dd3a7171344119015 100644 --- a/public/index.html +++ b/public/index.html @@ -1,11 +1,33 @@ <!DOCTYPE html> -<html lang="fr"> +<html lang="fr" prefix="og: https://ogp.me/ns#"> <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="description" + content="Créations numériques, jeux vidéos, web, software et pédagogie. Made in Ardèche, Vernoux en Vivarais." + /> + + <!-- Open Graph Protocol meta data --> + <meta property="og:title" content="Kuadrado Software" /> + <meta + property="og:description" + content="Créations numériques, jeu vidéo, web, software et pédagogie. Made in Ardèche, Vernoux en Vivarais." + /> + <meta property="og:type" content="website" /> + <meta property="og:url" content="https://kuadrado-software.fr" /> + <meta + property="og:image" + content="https://kuadrado-software.fr/assets/images/logo_kuadrado.svg" + /> + <meta property="og:locale" content="fr_FR" /> + + <!-- English translation not ready yet --> + <!-- <meta property="og:locale:alternate" content="en_GB" /> --> + <!-- END OGP --> + <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> - <link rel="icon" type="image/svg+xml" href="/favicon.svg"> + <link rel="icon" type="image/svg+xml" href="/favicon.svg" /> <link href="/style/style.css" rel="stylesheet" /> </head> <body> diff --git a/public/main.js b/public/main.js index 0c2570ce3469f824bacf56a56842a7d0b96686c8..4438268822df27fc8867c34bfbe758b790507998 100644 --- a/public/main.js +++ b/public/main.js @@ -8,6 +8,10 @@ function getServerUrl() { module.exports = { getServerUrl, website_title: "Kuadrado website template", + build: { + protected_dirs: ["assets", "style", "articles"], + default_meta_keys: ["title", "description", "open_graph"], + }, }; },{}],2:[function(require,module,exports){ diff --git a/public/software-development/index.html b/public/software-development/index.html index 593f1fb7b23587c6076a6e566a514f609a90d791..e2c3f8d070ee490ea64551ae323cae459af3a866 100644 --- a/public/software-development/index.html +++ b/public/software-development/index.html @@ -1,11 +1,24 @@ <!DOCTYPE html> -<html lang="fr"> +<html lang="fr" prefix="og: https://ogp.me/ns#"> <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."/> + + <!-- Open Graph Protocol meta data --> + <meta property="og:title" content="Kuadrado Software | Software" /> + <meta property="og:description" content="Développement web, moteur de jeux, outillage logiciel, retrouvez nos projets en détail." /> + <meta property="og:type" content="website" /> + <meta property="og:url" content="https://kuadrado-software.fr/software-development" /> + <meta property="og:image" content="https://kuadrado-software.fr/assets/images/meca_proc.svg" /> + <meta property="og:locale" content="fr_FR" /> + + <!-- English translation not ready yet --> + <!-- <meta property="og:locale:alternate" content="en_GB" /> --> + <!-- END OGP --> + <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> - <link rel="icon" type="image/svg+xml" href="/favicon.svg"> + <link rel="icon" type="image/svg+xml" href="/favicon.svg" /> <link href="/style/style.css" rel="stylesheet" /> </head> <body> diff --git a/public/software-development/software-development.js b/public/software-development/software-development.js index 21782ffe7106980abc8e8d220d63b68c82c6861e..3e2d6474fc0ca8afb43b6b346cd8aa121078a190 100644 --- a/public/software-development/software-development.js +++ b/public/software-development/software-development.js @@ -8,6 +8,10 @@ function getServerUrl() { module.exports = { getServerUrl, website_title: "Kuadrado website template", + build: { + protected_dirs: ["assets", "style", "articles"], + default_meta_keys: ["title", "description", "open_graph"], + }, }; },{}],2:[function(require,module,exports){ diff --git a/src/pages/education/meta.json b/src/pages/education/meta.json index 3f229c5a6b5f5135976c5bd41fb098fa77363b67..3e1fe1fcecf7de8efeb7a0be38dc464b08f67aa3 100644 --- a/src/pages/education/meta.json +++ b/src/pages/education/meta.json @@ -1,4 +1,9 @@ { "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 + "description": "Animations autour de la création de jeux vidéos, vulgarisation numérique. Découvrez nos initiatives pédagogiques.", + "open_graph": { + "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.", + "image": "https://kuadrado-software.fr/assets/images/brain.svg" + } +} diff --git a/src/pages/games/meta.json b/src/pages/games/meta.json index 7476b5c4d50dfe6ddbb1b6275b8077f283c9111d..ae505b3e689b95aa25ba51e21509fe32f2c8a1f4 100644 --- a/src/pages/games/meta.json +++ b/src/pages/games/meta.json @@ -1,4 +1,9 @@ { "title": "Kuadrado Software | Jeux", - "description": "Création de jeux vidéos indépendants. Jeux web, PC et projets en cours de développement" + "description": "Création de jeux vidéos indépendants. Jeux web, PC et projets en cours de développement", + "open_graph": { + "title": "Kuadrado Software | Jeux", + "description": "Création de jeux vidéos indépendants. Jeux web, PC et projets en cours de développement", + "image": "https://kuadrado-software.fr/assets/images/game_controller.svg" + } } \ No newline at end of file diff --git a/src/pages/software-development/meta.json b/src/pages/software-development/meta.json index b6f4d515abdbc5d84205743c337383cd56a0f74c..12ff687a627823c269108f2cc9a7023a691e9951 100644 --- a/src/pages/software-development/meta.json +++ b/src/pages/software-development/meta.json @@ -1,4 +1,9 @@ { "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 + "description": "Développement web, moteur de jeux, outillage logiciel, retrouvez nos projets en détail.", + "open_graph": { + "title": "Kuadrado Software | Software", + "description": "Développement web, moteur de jeux, outillage logiciel, retrouvez nos projets en détail.", + "image": "https://kuadrado-software.fr/assets/images/meca_proc.svg" + } +}