Skip to content

Commit

Permalink
Resolves #13 - Pulling data from info page
Browse files Browse the repository at this point in the history
  • Loading branch information
reneweiser committed Sep 19, 2020
1 parent 70a6e88 commit 4029c19
Showing 1 changed file with 54 additions and 35 deletions.
89 changes: 54 additions & 35 deletions src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,50 +1,69 @@
<script>
import { Router } from "@sveltech/routify";
import { metatags } from "@sveltech/routify";
import { metatags, ready } from "@sveltech/routify";
import { routes } from "../.routify/routes";
import { processInfo } from "./js/wpResponseParser.js";
import { checkExternalLinks } from "./js/externalLinks.js";
import { checkExternalLinks } from './js/externalLinks.js';
metatags.title = "Robin Weißenborn"; // site.title
metatags.author = "Robin Weißenborn"; // site.contact.name
metatags.description = "Description..."; // site.description
metatags.keywords = "tag1, tag2,"; // site.tags
metatags.generator = "encoding.group";
metatags["geo.region"] = "DE";
metatags["og:type"] = "website";
metatags["og:url"] = "https://robinweissenborn.de"; // site.url
metatags["og:image"] = "image"; // site.image
metatags["og:locale"] = "de_DE";
let jsonld = {
"@context": "https://schema.org",
"@type": "Person",
workLocation: {
"@type": "PostalAddress",
addressLocality: "", // site.contact.address1.city,
postalCode: "", // site.contact.address1.zip,
streetAddress: "", // site.contact.address1.street
},
name: "", // site.contact.name,
alternateName: "Robin Weissenborn", // replace ß with ss
description: "", // site.description,
additionalType: "Artist",
email: "", // "mailto:"+site.contact.mail,
image: "", // site.image,
jobTitle: "", // "Graphic Designer",
url: "", // site.url
};
let jsonld;
$: getData();
function getData() {
fetch("https://api.robinweissenborn.de/wp-json/wp/v2/pages?slug=info")
.then((response) => response.json())
.then((json) => {
getMeta(json[0]);
jsonld = getJsonLd(json[0])
$ready();
});
}
function getMeta(data) {
metatags.title = `${data.acf.contact.first_name} ${data.acf.contact.last_name}`;
metatags.author = `${data.acf.contact.first_name} ${data.acf.contact.last_name}`;
metatags.description = data.acf["website-metadata"].description;
metatags.keywords = data.acf["website-metadata"].keywords;
metatags.generator = "encoding.group";
metatags["geo.region"] = "DE";
metatags["og:type"] = "website";
metatags["og:url"] = "https://robinweissenborn.de"; // site.url
metatags["og:image"] = data.acf["website-metadata"].image;
metatags["og:locale"] = "de_DE";
}
function getJsonLd(data) {
return JSON.stringify({
"@context": "https://schema.org",
"@type": "Person",
workLocation: {
"@type": "PostalAddress",
addressLocality: data.acf["address-1"].city,
postalCode: data.acf["address-1"].zip_code,
streetAddress: data.acf["address-1"].street,
},
name: `${data.acf.contact.first_name} ${data.acf.contact.last_name}`,
alternateName: `${data.acf.contact.first_name} ${data.acf.contact.last_name}`.replace(
/ß/g,
"ss"
),
description: data.acf["website-metadata"].description,
additionalType: "Artist",
email: data.acf.contact.email,
image: data.acf["website-metadata"].image,
jobTitle: "Graphic Designer",
url: "https://robinweissenborn.de", // site.url
});
}
</script>

<style type="text/scss" global>
@import "../static/global.css";
</style>

<svelte:window on:click={checkExternalLinks}></svelte:window>
<svelte:window on:click={checkExternalLinks} />

<svelte:head>
<!-- {@html `<script type="application/ld+json">${JSON.stringify(jsonld)}</script>`} -->
{@html '<script type="application/ld+json">' + jsonld + '</script>'}
</svelte:head>

<Router {routes} />

0 comments on commit 4029c19

Please sign in to comment.