diff --git a/gatsby/lobid/gatsby-config.js b/gatsby/lobid/gatsby-config.js index 4673e468..ab847327 100644 --- a/gatsby/lobid/gatsby-config.js +++ b/gatsby/lobid/gatsby-config.js @@ -25,6 +25,12 @@ module.exports = { path: `${__dirname}/static/publication/`, } }, + { + resolve: `gatsby-source-filesystem`, + options: { + path: `${__dirname}/static/product/`, + } + }, `gatsby-transformer-sharp`, `gatsby-plugin-sharp` ], diff --git a/gatsby/lobid/gatsby-node.js b/gatsby/lobid/gatsby-node.js index 513b52c5..67073d76 100644 --- a/gatsby/lobid/gatsby-node.js +++ b/gatsby/lobid/gatsby-node.js @@ -23,6 +23,8 @@ exports.createPages = async ({ graphql, actions }) => { context: { lang: "en" }, }); + // Pages for individual members listed in `membership` + const { data: { members }, } = await graphql(` @@ -37,25 +39,37 @@ exports.createPages = async ({ graphql, actions }) => { } `); - const nodeArray = members.membership - .map(membership => membership.member.id) + const shortMemberIds = members.membership.map(m => m.member.id) .filter(id => id.indexOf("lobid.org/team") != -1) .map(id => id.slice(id.lastIndexOf("/") + 1, id.lastIndexOf("!#") - 1)); - const unique = [...new Set(nodeArray)]; - unique.forEach((member) => { - createPage({ - path: `/team/${member}`, - component: path.resolve(`./src/templates/member.js`), - context: { id: member }, - }); - }); + addPages(shortMemberIds, "team", "./src/templates/member.js", createPage); + + // Pages for individual products listed in `makesOffer` + + const { + data: { products }, + } = await graphql(` + { + products: dataJson { + makesOffer { + id + } + } + } + `); + + const shortProductIds = products.makesOffer.map(p => p.id) + .filter(id => id.indexOf("/") != -1) + .map(id => id.slice(id.lastIndexOf("/") + 1, id.lastIndexOf("."))); + addPages(shortProductIds, "product", "./src/templates/product.js", createPage); + }; // Create `fields.jsonFile` fields to link to static publication JSON files exports.onCreateNode = ({ node, getNode, actions }) => { const { createNodeField } = actions if (node.internal.type === "PublicationJson") { - + const relativeFilePath = createFilePath({ node, getNode, @@ -68,4 +82,15 @@ exports.onCreateNode = ({ node, getNode, actions }) => { value: `/publication${relativeFilePath}.json`, }) } -} \ No newline at end of file +} + +function addPages(ids, prefix, template, createPage) { + const unique = [...new Set(ids)]; + unique.forEach((member) => { + createPage({ + path: `/${prefix}/${member}`, + component: path.resolve(template), + context: { id: member }, + }); + }); +} diff --git a/gatsby/lobid/src/components/helpers.js b/gatsby/lobid/src/components/helpers.js new file mode 100644 index 00000000..76899cd1 --- /dev/null +++ b/gatsby/lobid/src/components/helpers.js @@ -0,0 +1,3 @@ +export function simpleId(url) { + return url.slice(url.lastIndexOf("/") + 1, url.lastIndexOf(".")); +} diff --git a/gatsby/lobid/src/components/member.html.js b/gatsby/lobid/src/components/member.html.js index 49b42f9c..064aa6bc 100644 --- a/gatsby/lobid/src/components/member.html.js +++ b/gatsby/lobid/src/components/member.html.js @@ -3,6 +3,7 @@ import md5 from 'md5'; import Header from "./header.html"; import Footer from "./footer.html"; +import Publications from "./publications.html"; import "./css/lobid.css"; import "./css/bootstrap.min.css"; @@ -65,33 +66,7 @@ export class Member extends React.Component { {this.props.member.name.label} - {this.props.pubs.length > 0 && -
-
-

{this.props.publications}

- - - - - - {this.props.pubs.map(publication => - - - - - - - - )} - - - -
{publication.datePublished}{publication.name.de || publication.name.en || publication.id}{publication.about && publication.about.map(a => -

 {a.id.split("://")[1].split(".")[0]}

- )}
{publication.type}JSON-LD
-
-
- } +