Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": "example.com"
}
```

## Run with test data

Expand Down
30 changes: 28 additions & 2 deletions lib/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -93,16 +112,23 @@ 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
template: multiPageConfig.root.template,
domain: 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: domain
};
break; // Only need to match one type
}
Expand Down
18 changes: 12 additions & 6 deletions test_data/thipe-ayeye/templates/thipe-ayeye-about-template.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
<html lang="en">
<head>
{# Facebook sharing image (Open Graph) #}
<meta property="og:url" content="https://ayeye-thipe-akerte.bird-apps.com/ro-crate-preview.html" />
<meta property="og:type" content="website" />
<meta property="og:title" content="Ayeye Thipe Akerte" />
<meta property="og:description" content="Arrernte stories about birds" />
<meta property="og:image" content="http://ayeye-thipe-akerte.bird-apps.com/files/images/og-img.jpg" />
<meta property="og:image:secure_url" content="https://ayeye-thipe-akerte.bird-apps.com/files/images/og-img.jpg" />
{% set domain = data.pages[data.entryPoint].domain %}
{% set path = data.pages[data.entryPoint].path %}

{% if domain %}
<meta property="og:url" content="https://{{ domain }}/{{ path }}" />
<meta property="og:image" content="http://{{ domain }}/files/images/og-img.jpg" />
<meta property="og:image:secure_url" content="https://{{ domain }}/files/images/og-img.jpg" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
{% endif %}

<meta property="og:type" content="website" />
<meta property="og:title" content="{{ data.ids[data.entryPoint].props["http://schema.org/name"].fwd[0].value if data.ids[data.entryPoint].props["http://schema.org/name"] }}" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be safest to wrap both the name and description tags in conditions that only write the respective tags if there's content, rather than writing a tag with blank content. Same for the other templates.

<meta property="og:description" content="{{ data.ids[data.entryPoint].props["http://schema.org/description"].fwd[0].value if data.ids[data.entryPoint].props["http://schema.org/description"] }}" />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ title }}</title>
Expand Down
19 changes: 13 additions & 6 deletions test_data/thipe-ayeye/templates/thipe-ayeye-person-template.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
<html lang="en">
<head>
{# Facebook sharing image (Open Graph) #}
<meta property="og:url" content="https://ayeye-thipe-akerte.bird-apps.com/ro-crate-preview.html" />
<meta property="og:type" content="website" />
<meta property="og:title" content="Ayeye Thipe Akerte" />
<meta property="og:description" content="Arrernte stories about birds" />
<meta property="og:image" content="http://ayeye-thipe-akerte.bird-apps.com/files/images/og-img.jpg" />
<meta property="og:image:secure_url" content="https://ayeye-thipe-akerte.bird-apps.com/files/images/og-img.jpg" />

{% set domain = data.pages[data.entryPoint].domain %}
{% set path = data.pages[data.entryPoint].path %}

{% if domain %}
<meta property="og:url" content="https://{{ domain }}/{{ path }}" />
<meta property="og:image" content="http://{{ domain }}/files/images/og-img.jpg" />
<meta property="og:image:secure_url" content="https://{{ domain }}/files/images/og-img.jpg" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
{% endif %}

<meta property="og:type" content="website" />
<meta property="og:title" content="{{ data.ids[data.entryPoint].props["http://schema.org/name"].fwd[0].value if data.ids[data.entryPoint].props["http://schema.org/name"] }}" />
<meta property="og:description" content="{{ data.ids[data.entryPoint].props["http://schema.org/description"].fwd[0].value if data.ids[data.entryPoint].props["http://schema.org/description"] }}" />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ title }}</title>
Expand Down
19 changes: 13 additions & 6 deletions test_data/thipe-ayeye/templates/thipe-ayeye-root-template.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
<html lang="en">
<head>
{# Facebook sharing image (Open Graph) #}
<meta property="og:url" content="https://ayeye-thipe-akerte.bird-apps.com/ro-crate-preview.html" />
<meta property="og:type" content="website" />
<meta property="og:title" content="Ayeye Thipe Akerte" />
<meta property="og:description" content="Arrernte stories about birds" />
<meta property="og:image" content="http://ayeye-thipe-akerte.bird-apps.com/files/images/og-img.jpg" />
<meta property="og:image:secure_url" content="https://ayeye-thipe-akerte.bird-apps.com/files/images/og-img.jpg" />

{% set domain = data.pages[data.entryPoint].domain %}
{% set path = data.pages[data.entryPoint].path %}

{% if domain %}
<meta property="og:url" content="https://{{ domain }}/{{ path }}" />
<meta property="og:image" content="http://{{ domain }}/files/images/og-img.jpg" />
<meta property="og:image:secure_url" content="https://{{ domain }}/files/images/og-img.jpg" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
{% endif %}

<meta property="og:type" content="website" />
<meta property="og:title" content="{{ data.ids[data.entryPoint].props["http://schema.org/name"].fwd[0].value if data.ids[data.entryPoint].props["http://schema.org/name"] }}" />
<meta property="og:description" content="{{ data.ids[data.entryPoint].props["http://schema.org/description"].fwd[0].value if data.ids[data.entryPoint].props["http://schema.org/description"] }}" />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ title }}</title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ title }}</title>

{# Facebook sharing image (Open Graph) #}
<meta property="og:url" content="{{ url }}" />
<meta property="og:type" content="website" />
<meta property="og:title" content="{{ data.ids[data.entryPoint].props['http://schema.org/name'].fwd[0].value }}" />
<meta property="og:description" content="{{ data.ids[data.entryPoint].props.sentence.fwd[0].value }}" />
<meta name="description" content="{{ data.ids[data.entryPoint].props.sentence.fwd[0].value }}" />
{% if data.ids[data.entryPoint].props["http://schema.org/hasPart"] %}
<meta property="og:title" content="{{ data.ids[data.entryPoint].props['http://schema.org/name'].fwd[0].value }}" />
<meta property="og:description" content="{{ data.ids[data.entryPoint].props.sentence.fwd[0].value }}" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This didn't work for me. Try replacing
data.ids[data.entryPoint].props.sentence.fwd[0].value with
data.ids[data.entryPoint].props['arcp://name,custom/terms#sentence'].fwd[0].value

similar for ln 11 below

<meta name="description" content="{{ data.ids[data.entryPoint].props.sentence.fwd[0].value }}" />

{% 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"] %}
<meta property="og:url" content="https://{{ domain }}/{{ path }}" />
{% 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")) %}
<meta property="og:image" content="http://ayeye-thipe-akerte.bird-apps.com/{{ val.target_name }}" />
<meta property="og:image:secure_url" content="https://ayeye-thipe-akerte.bird-apps.com/{{ val.target_name }}" />
<meta property="og:image" content="http://{{ domain }}/{{ val.target_name }}" />
<meta property="og:image:secure_url" content="https://{{ domain }}/{{ val.target_name }}" />
{% endif %}
{% endfor %}
{% endif %}
Expand Down
3 changes: 2 additions & 1 deletion test_data/thipe-ayeye/thipe-ayeye-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "ayeye-thipe-akerte.bird-apps.com"
}