From c8e073d5d8313954196ab6941073de8fda9c84d2 Mon Sep 17 00:00:00 2001 From: Casey-Haseloff Date: Thu, 2 Oct 2025 13:56:34 +1000 Subject: [PATCH 1/4] remove hard coded values and add domain --- README.md | 10 +++++++++- lib/preview.js | 6 ++++-- .../templates/thipe-ayeye-about-template.html | 17 +++++++++++------ .../templates/thipe-ayeye-person-template.html | 18 ++++++++++++------ .../templates/thipe-ayeye-root-template.html | 18 ++++++++++++------ .../thipe-ayeye-subobject-template.html | 16 ++++++++++------ test_data/thipe-ayeye/thipe-ayeye-config.json | 3 ++- 7 files changed, 60 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 8343ec6..7ebc984 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,15 @@ To generate an About page for the site: 3. Associate the `AboutPage` type with a template in the multipage config. - +### Domain +To add domain to open graph metadata tags: +1. Add domain to the multipage config +```json +{ + "root": {"template":"test_data/example/templates/example-template.html"}, + "domain": "https://example.com" +} +``` ## Run with test data diff --git a/lib/preview.js b/lib/preview.js index 5d101ec..6841432 100644 --- a/lib/preview.js +++ b/lib/preview.js @@ -95,14 +95,16 @@ async function roCrateToJSON(crate, multiPageConfig) { console.log("Generating pages based on multi-page configuration..."); crateLite.pages[crate.rootDataset["@id"]] = { path: "ro-crate-preview.html", - template: multiPageConfig.root.template + template: multiPageConfig.root.template, + domain: multiPageConfig.domain }; for (let entity of crate.entities()) { for (let type of entity["@type"]) { if (multiPageConfig.types[type]) { crateLite.pages[entity["@id"]] = { path: "ro-crate-preview_html/" + quadTreeId(entity["@id"]), - template: multiPageConfig.types[type].template + template: multiPageConfig.types[type].template, + domain: multiPageConfig.domain }; break; // Only need to match one type } diff --git a/test_data/thipe-ayeye/templates/thipe-ayeye-about-template.html b/test_data/thipe-ayeye/templates/thipe-ayeye-about-template.html index 3706e0b..8e5497f 100644 --- a/test_data/thipe-ayeye/templates/thipe-ayeye-about-template.html +++ b/test_data/thipe-ayeye/templates/thipe-ayeye-about-template.html @@ -1,14 +1,19 @@ {# Facebook sharing image (Open Graph) #} - - - - - - + {% set domain = data.pages[data.entryPoint].domain %} + + {% if domain %} + + + + {% endif %} + + + + {{ title }} diff --git a/test_data/thipe-ayeye/templates/thipe-ayeye-person-template.html b/test_data/thipe-ayeye/templates/thipe-ayeye-person-template.html index bf3c769..58ca390 100644 --- a/test_data/thipe-ayeye/templates/thipe-ayeye-person-template.html +++ b/test_data/thipe-ayeye/templates/thipe-ayeye-person-template.html @@ -1,14 +1,20 @@ {# Facebook sharing image (Open Graph) #} - - - - - - + + {% set domain = data.pages[data.entryPoint].domain %} + + {% if domain %} + + + + {% endif %} + + + + {{ title }} diff --git a/test_data/thipe-ayeye/templates/thipe-ayeye-root-template.html b/test_data/thipe-ayeye/templates/thipe-ayeye-root-template.html index c792356..2b0b042 100644 --- a/test_data/thipe-ayeye/templates/thipe-ayeye-root-template.html +++ b/test_data/thipe-ayeye/templates/thipe-ayeye-root-template.html @@ -1,14 +1,20 @@ {# Facebook sharing image (Open Graph) #} - - - - - - + + {% set domain = data.pages[data.entryPoint].domain %} + + {% if domain %} + + + + {% endif %} + + + + {{ title }} diff --git a/test_data/thipe-ayeye/templates/thipe-ayeye-subobject-template.html b/test_data/thipe-ayeye/templates/thipe-ayeye-subobject-template.html index 41ff23b..1f088b2 100644 --- a/test_data/thipe-ayeye/templates/thipe-ayeye-subobject-template.html +++ b/test_data/thipe-ayeye/templates/thipe-ayeye-subobject-template.html @@ -3,17 +3,21 @@ {{ title }} + {# Facebook sharing image (Open Graph) #} - - - - {% if data.ids[data.entryPoint].props["http://schema.org/hasPart"] %} + + + + + {% set domain = data.pages[data.entryPoint].domain %} + + {% if domain and data.ids[data.entryPoint].props["http://schema.org/hasPart"] %} {% for val in data.ids[data.entryPoint].props["http://schema.org/hasPart"].fwd %} {% if val.target_name and (val.target_name.endsWith(".jpg") or val.target_name.endsWith(".png")) %} - - + + {% endif %} {% endfor %} {% endif %} diff --git a/test_data/thipe-ayeye/thipe-ayeye-config.json b/test_data/thipe-ayeye/thipe-ayeye-config.json index 37008a4..412ad8a 100644 --- a/test_data/thipe-ayeye/thipe-ayeye-config.json +++ b/test_data/thipe-ayeye/thipe-ayeye-config.json @@ -4,5 +4,6 @@ "Person": {"template": "test_data/thipe-ayeye/templates/thipe-ayeye-person-template.html"}, "AboutPage": {"template": "test_data/thipe-ayeye/templates/thipe-ayeye-about-template.html"} }, - "root" : {"template": "test_data/thipe-ayeye/templates/thipe-ayeye-root-template.html"} + "root" : {"template": "test_data/thipe-ayeye/templates/thipe-ayeye-root-template.html"}, + "domain": "https://ayeye-thipe-akerte.bird-apps.com" } From f34d6a3a8c70b02f1a698bbd96b528a74b5e0908 Mon Sep 17 00:00:00 2001 From: Casey-Haseloff Date: Thu, 9 Oct 2025 12:38:06 +1000 Subject: [PATCH 2/4] validate domain and update path --- README.md | 2 +- lib/preview.js | 28 +++++++++++++++++-- .../templates/thipe-ayeye-about-template.html | 3 +- .../thipe-ayeye-person-template.html | 3 +- .../templates/thipe-ayeye-root-template.html | 5 ++-- .../thipe-ayeye-subobject-template.html | 3 +- test_data/thipe-ayeye/thipe-ayeye-config.json | 2 +- 7 files changed, 37 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7ebc984..8775df4 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ To add domain to open graph metadata tags: ```json { "root": {"template":"test_data/example/templates/example-template.html"}, - "domain": "https://example.com" + "domain": "example.com" } ``` diff --git a/lib/preview.js b/lib/preview.js index 6841432..01ac33b 100644 --- a/lib/preview.js +++ b/lib/preview.js @@ -81,6 +81,25 @@ function quadTreeId(id) { return `${part1}/${part2}/${part3}/${part4}/index.html`; } +function validateDomain(domain) { + // remove protocol (http://, https://) and trailing slashes + const cleaned = domain + .trim() + .replace(/^https?:\/\//, '') + .replace(/\/+$/, ''); + + // check valid domain pattern + const domainPattern = /^(?!-)(?:[a-zA-Z0-9-]{1,63}\.)+[a-zA-Z]{2,}$/; + + if (!domainPattern.test(cleaned)) { + console.log(`Invalid domain: "${domain}"`) + return null; + } + + console.log(`Valid domain: "${domain}"`) + return cleaned; +} + async function roCrateToJSON(crate, multiPageConfig) { const crateLite = { entryPoint: crate.rootDataset["@id"], @@ -93,10 +112,15 @@ async function roCrateToJSON(crate, multiPageConfig) { // First pass to create pages if multiPageConfig is provided if (multiPageConfig) { console.log("Generating pages based on multi-page configuration..."); + + const domain = multiPageConfig.domain + ? validateDomain(multiPageConfig.domain) + : null; + crateLite.pages[crate.rootDataset["@id"]] = { path: "ro-crate-preview.html", template: multiPageConfig.root.template, - domain: multiPageConfig.domain + domain: domain }; for (let entity of crate.entities()) { for (let type of entity["@type"]) { @@ -104,7 +128,7 @@ async function roCrateToJSON(crate, multiPageConfig) { crateLite.pages[entity["@id"]] = { path: "ro-crate-preview_html/" + quadTreeId(entity["@id"]), template: multiPageConfig.types[type].template, - domain: multiPageConfig.domain + domain: domain }; break; // Only need to match one type } diff --git a/test_data/thipe-ayeye/templates/thipe-ayeye-about-template.html b/test_data/thipe-ayeye/templates/thipe-ayeye-about-template.html index 8e5497f..2274fee 100644 --- a/test_data/thipe-ayeye/templates/thipe-ayeye-about-template.html +++ b/test_data/thipe-ayeye/templates/thipe-ayeye-about-template.html @@ -2,9 +2,10 @@ {# Facebook sharing image (Open Graph) #} {% set domain = data.pages[data.entryPoint].domain %} + {% set path = data.pages[data.entryPoint].path %} {% if domain %} - + diff --git a/test_data/thipe-ayeye/templates/thipe-ayeye-person-template.html b/test_data/thipe-ayeye/templates/thipe-ayeye-person-template.html index 58ca390..45e1e4c 100644 --- a/test_data/thipe-ayeye/templates/thipe-ayeye-person-template.html +++ b/test_data/thipe-ayeye/templates/thipe-ayeye-person-template.html @@ -3,9 +3,10 @@ {# Facebook sharing image (Open Graph) #} {% set domain = data.pages[data.entryPoint].domain %} + {% set path = data.pages[data.entryPoint].path %} {% if domain %} - + diff --git a/test_data/thipe-ayeye/templates/thipe-ayeye-root-template.html b/test_data/thipe-ayeye/templates/thipe-ayeye-root-template.html index 2b0b042..1ec34c1 100644 --- a/test_data/thipe-ayeye/templates/thipe-ayeye-root-template.html +++ b/test_data/thipe-ayeye/templates/thipe-ayeye-root-template.html @@ -3,9 +3,10 @@ {# Facebook sharing image (Open Graph) #} {% set domain = data.pages[data.entryPoint].domain %} - + {% set path = data.pages[data.entryPoint].path %} + {% if domain %} - + diff --git a/test_data/thipe-ayeye/templates/thipe-ayeye-subobject-template.html b/test_data/thipe-ayeye/templates/thipe-ayeye-subobject-template.html index 1f088b2..7824618 100644 --- a/test_data/thipe-ayeye/templates/thipe-ayeye-subobject-template.html +++ b/test_data/thipe-ayeye/templates/thipe-ayeye-subobject-template.html @@ -5,15 +5,16 @@ {{ title }} {# Facebook sharing image (Open Graph) #} - {% set domain = data.pages[data.entryPoint].domain %} + {% set path = data.pages[data.entryPoint].path %} {% if domain and data.ids[data.entryPoint].props["http://schema.org/hasPart"] %} + {% for val in data.ids[data.entryPoint].props["http://schema.org/hasPart"].fwd %} {% if val.target_name and (val.target_name.endsWith(".jpg") or val.target_name.endsWith(".png")) %} diff --git a/test_data/thipe-ayeye/thipe-ayeye-config.json b/test_data/thipe-ayeye/thipe-ayeye-config.json index 412ad8a..1251482 100644 --- a/test_data/thipe-ayeye/thipe-ayeye-config.json +++ b/test_data/thipe-ayeye/thipe-ayeye-config.json @@ -5,5 +5,5 @@ "AboutPage": {"template": "test_data/thipe-ayeye/templates/thipe-ayeye-about-template.html"} }, "root" : {"template": "test_data/thipe-ayeye/templates/thipe-ayeye-root-template.html"}, - "domain": "https://ayeye-thipe-akerte.bird-apps.com" + "domain": "ayeye-thipe-akerte.bird-apps.com" } From 51970a4f695b52d0b1cf7493c5382ad5c87c2dcf Mon Sep 17 00:00:00 2001 From: Casey-Haseloff Date: Thu, 9 Oct 2025 13:47:12 +1000 Subject: [PATCH 3/4] url https --- .../thipe-ayeye/templates/thipe-ayeye-about-template.html | 6 +++++- .../thipe-ayeye/templates/thipe-ayeye-person-template.html | 2 +- .../thipe-ayeye/templates/thipe-ayeye-root-template.html | 2 +- .../templates/thipe-ayeye-subobject-template.html | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test_data/thipe-ayeye/templates/thipe-ayeye-about-template.html b/test_data/thipe-ayeye/templates/thipe-ayeye-about-template.html index 2274fee..53aaf22 100644 --- a/test_data/thipe-ayeye/templates/thipe-ayeye-about-template.html +++ b/test_data/thipe-ayeye/templates/thipe-ayeye-about-template.html @@ -5,7 +5,7 @@ {% set path = data.pages[data.entryPoint].path %} {% if domain %} - + @@ -58,6 +58,10 @@ +
+ {{ data | dump }} +
+ {% macro root() %}