Skip to content

Commit

Permalink
Set up product pages with related publications (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteeg committed Jul 7, 2021
1 parent 2b04679 commit e1d3e12
Show file tree
Hide file tree
Showing 13 changed files with 402 additions and 57 deletions.
6 changes: 6 additions & 0 deletions gatsby/lobid/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
],
Expand Down
49 changes: 37 additions & 12 deletions gatsby/lobid/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ exports.createPages = async ({ graphql, actions }) => {
context: { lang: "en" },
});

// Pages for individual members listed in `membership`

const {
data: { members },
} = await graphql(`
Expand All @@ -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,
Expand All @@ -68,4 +82,15 @@ exports.onCreateNode = ({ node, getNode, actions }) => {
value: `/publication${relativeFilePath}.json`,
})
}
}
}

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 },
});
});
}
3 changes: 3 additions & 0 deletions gatsby/lobid/src/components/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function simpleId(url) {
return url.slice(url.lastIndexOf("/") + 1, url.lastIndexOf("."));
}
29 changes: 2 additions & 27 deletions gatsby/lobid/src/components/member.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -65,33 +66,7 @@ export class Member extends React.Component {
<img alt={this.props.member.name.label} id="index-image" src={this.props.member.image || `https://gravatar.com/avatar/${md5(this.props.member.email)}?s=300&d=identicon`} />
</div>
</div>
{this.props.pubs.length > 0 &&
<div className="row">
<div className="col-md-12">
<p className="lead">{this.props.publications}</p>
<table className="table table-striped table-condensed">
<thead>
<tr><th width="10%" /><th width="65%" /><th width="12%" /><th width="10%" /><th width="3%" /></tr>
</thead>
<tbody>
{this.props.pubs.map(publication =>
<tr>
<td><small>{publication.datePublished}</small></td>
<td><a href={publication.id}>{publication.name.de || publication.name.en || publication.id}</a></td>
<td>{publication.about && publication.about.map(a =>
<p><small><span class="glyphicon glyphicon-tag" aria-hidden="true"></span></small>&nbsp;<a href={a.id}>{a.id.split("://")[1].split(".")[0]}</a></p>
)}</td>
<td align="right"><small><a href={"https://schema.org/" + publication.type}>{publication.type}</a></small></td>
<td><a title="Beschreibung als JSON-LD anzeigen" href={publication.fields.jsonFile}><img height="20px" src={jsonLdPng} alt="JSON-LD" /></a></td>
</tr>
)}

</tbody>
<tfoot />
</table>
</div>
</div>
}
<Publications pubs={this.props.pubs} publications={this.props.publications} />
<Footer companyDetails={this.props.companyDetails} privacy={this.props.privacy} />
</div>
</div>
Expand Down
76 changes: 76 additions & 0 deletions gatsby/lobid/src/components/product.html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React from "react";
import md5 from 'md5';
import { simpleId } from './helpers.js'

import Header from "./header.html";
import Footer from "./footer.html";
import Publications from "./publications.html";

import "./css/lobid.css";
import "./css/bootstrap.min.css";
import "./css/font-awesome.min.css";

import jsonLdPng from "./images/json-ld.png";

export class Product extends React.Component {

constructor(props) {
super(props);
this.props = props;
}

asLinks(field) {
return this.props.product[field] && <tr><td>{this.props[field]}</td><td>{this.props.product[field].map((link) =>
<div key={link.id}><a href={link.id}>{link.id.replace('https://', '').replace('http://', '')}</a><br /></div>
)}</td></tr>
}

render() {
return (
<div className="container">
<p />
<Header
language={this.props.language}
languageLink={this.props.languageLink}
languageTooltip={this.props.languageTooltip}
publications={this.props.publications}
teamLink={this.props.teamLink}
contactPointId={this.props.contactPointId}
/>
<div>
<div className="page-header">
<h1>
{this.props.product.name.label}
<small>
{this.props.product.slogan && [this.props.product.slogan].map(s => <span>&mdash; {s.label}</span>)}
<a title="Beschreibung als JSON-LD anzeigen" href={'/product/' + simpleId(this.props.product.id) + '.json'}><img className='json-ld-icon' src={jsonLdPng} alt="JSON-LD" /></a></small>
</h1>
</div>

<div className="row">
<div className="col-md-9">
<p className="lead">{this.props.product.description.label}</p>
<table className="table table-striped table-condensed">
<thead>
<tr><th width="20%" /><th width="80%" /></tr>
</thead>
<tbody>
<tr><td>Website</td><td><a href={this.props.product.id}>{this.props.product.id}</a></td></tr>
{this.asLinks("hasPart")}
{this.asLinks("isBasedOn")}
{this.asLinks("isRelatedTo")}
</tbody>
<tfoot />
</table>
</div>
<div className="col-md-3">
<img alt={this.props.product.name.label} id="index-image" src={this.props.product.image || `https://gravatar.com/avatar/${md5(this.props.product.id)}?s=300&d=identicon`} />
</div>
</div>
<Publications pubs={this.props.pubs} publications={this.props.publications} />
<Footer companyDetails={this.props.companyDetails} privacy={this.props.privacy} />
</div>
</div>
);
}
}
36 changes: 36 additions & 0 deletions gatsby/lobid/src/components/publications.html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from "react"
import { simpleId } from './helpers.js'

import jsonLdPng from "./images/json-ld.png";

export default class Publications extends React.Component {
render() {
return (
this.props.pubs.length > 0 &&
<div className="row">
<div className="col-md-12">
<p className="lead">{this.props.publications}</p>
<table className="table table-striped table-condensed">
<thead>
<tr><th width="10%" /><th width="65%" /><th width="12%" /><th width="10%" /><th width="3%" /></tr>
</thead>
<tbody>
{this.props.pubs.map(publication =>
<tr key={publication.id}>
<td><small>{publication.datePublished}</small></td>
<td><a href={publication.id}>{publication.name.de || publication.name.en || publication.id}</a></td>
<td>{publication.about && publication.about.map(a =>
<p key={a.id}><small><span className="glyphicon glyphicon-tag" aria-hidden="true"></span></small>&nbsp;<a href={a.id}>{simpleId(a.id)}</a></p>
)}</td>
<td align="right"><small><a href={"https://schema.org/" + publication.type}>{publication.type}</a></small></td>
<td><a title="Beschreibung als JSON-LD anzeigen" href={publication.fields.jsonFile}><img height="20px" src={jsonLdPng} alt="JSON-LD" /></a></td>
</tr>
)}
</tbody>
<tfoot />
</table>
</div>
</div>
)
}
}
41 changes: 23 additions & 18 deletions gatsby/lobid/src/components/team.html.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import md5 from 'md5';
import { simpleId } from './helpers.js'

import Header from "./header.html";
import Footer from "./footer.html";
Expand Down Expand Up @@ -29,8 +30,8 @@ export class Team extends React.Component {
return (
<div id="former">
{this.props.team.membership.filter(member => member.endDate)
.map((member) => [member, this.getDetails(member)]).map(([member, details]) =>
<div>
.map((member) => [member, this.getMemberDetails(member)]).map(([member, details]) =>
<div key={member.member.id}>
{this.getImage(
(details && details.node.email) || member.member.id,
details && details.node.image)}
Expand Down Expand Up @@ -62,12 +63,15 @@ export class Team extends React.Component {
);
}

getDetails = (member) => {
getMemberDetails = (member) => {
return this.props.members.filter(m => m.node.id === member.member.id)[0];
}

getOfferDetails = (offer) => {
return this.props.products.filter(p => p.node.id === offer.id)[0];
}

render() {
console.log('Header', Header);
return (
<div className="container">
<p />
Expand Down Expand Up @@ -111,6 +115,7 @@ export class Team extends React.Component {
<p>
{this.props.team.contactPoint.map((contactPoint) =>
<a
key={contactPoint.id}
target="_blank"
href={contactPoint.id}
rel="nofollow noopener noreferrer"
Expand All @@ -130,8 +135,8 @@ export class Team extends React.Component {
<h2>{this.props.memberName}</h2>

{this.props.team.membership.filter((member) => !member.endDate)
.map((member) => [member, this.getDetails(member)]).map(([member, details]) =>
<div>
.map((member) => [member, this.getMemberDetails(member)]).map(([member, details]) =>
<div key={member.member.id}>
{this.getImage(details.node.email, details.node.image)}
<p className="details">
{this.getName(details.node.id, details.node.name[this.props.lang])}{" "}<br />
Expand Down Expand Up @@ -162,18 +167,18 @@ export class Team extends React.Component {

<h2>{this.props.makesOfferName}</h2>

{this.props.team.makesOffer.map((offer) =>
<p>
<a
target="_blank"
rel="nofollow noopener noreferrer"
href={offer.id}
>
{offer.id}
</a>
<br />
{offer.name}
</p>
{this.props.team.makesOffer
.map((offer) => [offer, this.getOfferDetails(offer)]).map(([offer, details]) =>
<div key={offer.id}>
{this.getImage(offer.id, details.node.image)}
<p className="details">
<a href={"/product/" + simpleId(offer.id)}>
{offer.name}
</a>
<br />
{(details.node.slogan && details.node.slogan[this.props.lang]) || offer.name}
</p>
</div>
)}
</div>
<Footer companyDetails={this.props.companyDetails} privacy={this.props.privacy} />
Expand Down
Loading

0 comments on commit e1d3e12

Please sign in to comment.