- Updates to reference the new Richtext field from Strapi - Update to include feature image in RSS - General cleanups (removing a lot of console.log) - I think there's a nextjs update in there as well
125 lines
4.4 KiB
JavaScript
Executable file
125 lines
4.4 KiB
JavaScript
Executable file
import getConfig from 'next/config'
|
|
import "../../components/main.js"
|
|
import Layout from "../../components/main.js"
|
|
import FeatureImage from "../../components/featureimage.js"
|
|
import StorySideBar from '../../components/storysidebar.js'
|
|
import PublishedInfo from '../../components/publishedinfo.js'
|
|
import { getAllPosts, getSinglePost } from '../../data/external/cms'
|
|
import Image from "next/legacy/image";
|
|
import Head from 'next/head'
|
|
import config from "../../data/internal/config"
|
|
|
|
const Article = ({article_obj, sections, pagedata, stories, serverRuntimeConfig, config}) => {
|
|
if (!article_obj) return null
|
|
|
|
var featureImage
|
|
|
|
if (article_obj.FeatureImage.data) {
|
|
if (article_obj.FeatureImage.data.attributes.formats.large) {
|
|
featureImage = article_obj.FeatureImage.data.attributes.formats.large
|
|
featureImage.name = article_obj.FeatureImage.data.attributes.alternativeText
|
|
}
|
|
}
|
|
|
|
var article_desc = article_obj.Abstract.replace(new RegExp('<[^>]*>', 'g'), '')
|
|
|
|
var rssFeed
|
|
|
|
if (article_obj.project.data && article_obj.project.data.attributes.HasFeed == true) {
|
|
rssFeed = config.siteURL+"/feed/"+article_obj.project.data.attributes.Slug+"-feed.xml"
|
|
}
|
|
|
|
return ( <Layout sections={sections} pagedata={pagedata}>
|
|
<Head>
|
|
<meta name="twitter:card" content={ article_desc } key="twcard" />
|
|
<meta name="twitter:creator" content="angrybeanie" key="twhandle" />
|
|
<meta name="og:url" content={config.siteURL + "/news/" + article_obj.Slug}></meta>
|
|
<meta name="og:type" content="article"></meta>
|
|
<meta name="og:title" content={ article_obj.Title } key="title"></meta>
|
|
<meta name="og:description" content={ article_desc } key="description"></meta>
|
|
{ article_obj.FeatureImage.data != null &&
|
|
<meta name="og:image" content={serverRuntimeConfig.media_path + featureImage.url}></meta>
|
|
}
|
|
{ article_obj.project.data != null && article_obj.project.data.attributes.HasFeed == true &&
|
|
<link rel="alternate" type="application/rss+xml" title={article_obj.project.data.attributes.Title + " Feed"} href={rssFeed} />
|
|
}
|
|
</Head>
|
|
<div className="main_content col-md-9 col-sm-12">
|
|
{ article_obj.FeatureImage.data != null &&
|
|
<FeatureImage imagedata = {featureImage} basepath = {serverRuntimeConfig.media_path} ></FeatureImage>
|
|
}
|
|
<h1 className="page_title col-sm-12">{ article_obj.Title }</h1>
|
|
<PublishedInfo publishData={article_obj}></PublishedInfo>
|
|
<div className="article_body" dangerouslySetInnerHTML={{ __html: article_obj.FullBody }}></div>
|
|
</div>
|
|
<StorySideBar stories={stories} />
|
|
</Layout>
|
|
)
|
|
}
|
|
|
|
export default Article
|
|
|
|
export async function getStaticPaths() {
|
|
const posts = await getAllPosts()
|
|
const paths = posts.data.map((post) => ({
|
|
params: { slug: post.attributes.Slug },
|
|
}))
|
|
return {
|
|
paths,
|
|
fallback: true // false or 'blocking'
|
|
};
|
|
}
|
|
|
|
|
|
export async function getStaticProps({params}) {
|
|
const { serverRuntimeConfig, publicRuntimeConfig } = getConfig()
|
|
const conf = config
|
|
const slug = params.slug
|
|
|
|
const article_obj = await getSinglePost(slug)
|
|
|
|
var filters = {};
|
|
|
|
if (article_obj.project.data != null) {
|
|
filters = (
|
|
{
|
|
project: {
|
|
Slug: article_obj.project.data.attributes.Slug
|
|
}
|
|
})
|
|
}
|
|
|
|
const qs = require('qs')
|
|
const query = qs.stringify({
|
|
pagination: {
|
|
limit: 5
|
|
},
|
|
filters,
|
|
sort: ['publishedAt:desc']
|
|
}, {
|
|
encodeValuesOnly: true,
|
|
})
|
|
|
|
const storiesQuery = await fetch(serverRuntimeConfig.base_path + `articles?${query}`, {
|
|
headers: new Headers({
|
|
'Authorization': serverRuntimeConfig.strapi_token,
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
})
|
|
})
|
|
|
|
const storydata = await storiesQuery.json()
|
|
const stories = storydata.data
|
|
|
|
const pagedata = {
|
|
'title': "Angry Beanie - " + article_obj.Title
|
|
}
|
|
|
|
const secres = await fetch(serverRuntimeConfig.base_path + '/api/sections')
|
|
const secdata = await secres.json()
|
|
|
|
return {
|
|
props: { article_obj, sections: secdata, pagedata, stories, serverRuntimeConfig, config }, // will be passed to the page component as props
|
|
revalidate: 60
|
|
}
|
|
}
|
|
|