Updated to use Projects, will need to update CMS
first
This commit is contained in:
parent
8bf8c62f1c
commit
7e5a8f94b1
4 changed files with 58 additions and 24 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -15,6 +15,6 @@ yarn-error.log*
|
||||||
#ideaj
|
#ideaj
|
||||||
.idea/
|
.idea/
|
||||||
#Feeds
|
#Feeds
|
||||||
public/feeds/
|
public/feed/
|
||||||
public/sitemap*
|
public/sitemap*
|
||||||
|
|
||||||
|
|
|
||||||
35
data/external/cms.js
vendored
35
data/external/cms.js
vendored
|
|
@ -2,7 +2,6 @@ import getConfig from 'next/config'
|
||||||
|
|
||||||
export const getAllPosts = async (filter, page, limit) => {
|
export const getAllPosts = async (filter, page, limit) => {
|
||||||
|
|
||||||
console.log(filter + " " + page + " " + limit)
|
|
||||||
const { serverRuntimeConfig, publicRuntimeConfig } = getConfig()
|
const { serverRuntimeConfig, publicRuntimeConfig } = getConfig()
|
||||||
const qs = require('qs')
|
const qs = require('qs')
|
||||||
const qVal = []
|
const qVal = []
|
||||||
|
|
@ -18,17 +17,21 @@ export const getAllPosts = async (filter, page, limit) => {
|
||||||
var filters = {}
|
var filters = {}
|
||||||
|
|
||||||
if (filter) {
|
if (filter) {
|
||||||
|
const tagList = []
|
||||||
|
filter.data.forEach(tag => {
|
||||||
|
console.log(tag)
|
||||||
|
tagList.push(tag.attributes.Slug)
|
||||||
|
})
|
||||||
|
|
||||||
filters = {
|
filters = {
|
||||||
tags: {
|
tags: {
|
||||||
Slug: {
|
Slug: {
|
||||||
$contains: filter
|
$in: tagList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(filter)
|
|
||||||
|
|
||||||
const qArray = {
|
const qArray = {
|
||||||
sort: ['publishedAt:desc'],
|
sort: ['publishedAt:desc'],
|
||||||
pagination: {
|
pagination: {
|
||||||
|
|
@ -88,3 +91,27 @@ export const getAllPodcastSeries = async () => {
|
||||||
|
|
||||||
return await res.json()
|
return await res.json()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getProjectDetails = async (projectId) => {
|
||||||
|
const { serverRuntimeConfig } = getConfig()
|
||||||
|
const qs = require('qs')
|
||||||
|
const query = qs.stringify({
|
||||||
|
filters: {
|
||||||
|
Slug: {
|
||||||
|
$eq: projectId
|
||||||
|
}
|
||||||
|
},
|
||||||
|
populate: '*'
|
||||||
|
}, {
|
||||||
|
encodeValuesOnly: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
const res = await fetch(serverRuntimeConfig.base_path + `projects?${query}`, {
|
||||||
|
headers: new Headers({
|
||||||
|
'Authorization': serverRuntimeConfig.strapi_token,
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return await res.json()
|
||||||
|
}
|
||||||
|
|
@ -1,19 +1,23 @@
|
||||||
import { Feed } from "feed"
|
import { Feed } from "feed"
|
||||||
import { getAllPodcastSeries, getAllPosts } from "../external/cms"
|
import { getAllPodcastSeries, getAllPosts, getProjectDetails } from "../external/cms"
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
import config from './config'
|
import config from './config'
|
||||||
|
|
||||||
export const generateRssFeed = async (filter) => {
|
export const generateRssFeed = async (filter) => {
|
||||||
|
|
||||||
const posts = await getAllPosts(filter);
|
const project = await getProjectDetails(filter);
|
||||||
|
|
||||||
|
const posts = await getAllPosts(project.data[0].attributes.tags);
|
||||||
|
|
||||||
const siteURL = config.siteURL;
|
const siteURL = config.siteURL;
|
||||||
|
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
|
|
||||||
const Title = typeof filter === "undefined" ? "Angry Beanie" : filter
|
const Title = typeof filter === "undefined" ? "Angry Beanie" : project.data[0].attributes.Title
|
||||||
|
|
||||||
const feedTitle = typeof filter === "undefined" ? "Angry-Beanie" : filter
|
const Description = typeof filter == "undefined" ? "A place for all my thoughts and projects" : project.data[0].attributes.Description
|
||||||
|
|
||||||
|
const feedTitle = typeof filter === "undefined" ? "Angry-Beanie" : project.data[0].attributes.Slug
|
||||||
|
|
||||||
const author = {
|
const author = {
|
||||||
|
|
||||||
|
|
@ -29,7 +33,7 @@ export const generateRssFeed = async (filter) => {
|
||||||
|
|
||||||
title: Title,
|
title: Title,
|
||||||
|
|
||||||
description: "A place for all my thoughts and projects",
|
description: Description,
|
||||||
|
|
||||||
id: siteURL,
|
id: siteURL,
|
||||||
|
|
||||||
|
|
@ -47,11 +51,11 @@ export const generateRssFeed = async (filter) => {
|
||||||
|
|
||||||
feedLinks: {
|
feedLinks: {
|
||||||
|
|
||||||
rss2: `${siteURL}/feeds/${feedTitle}-feed.xml`,
|
rss2: `${siteURL}/feed/${feedTitle}-feed.xml`,
|
||||||
|
|
||||||
json: `${siteURL}/feeds/${feedTitle}-feed.json`,
|
json: `${siteURL}/feed/${feedTitle}-feed.json`,
|
||||||
|
|
||||||
atom: `${siteURL}/feeds/${feedTitle}-atom.xml`,
|
atom: `${siteURL}/feed/${feedTitle}-atom.xml`,
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -85,13 +89,13 @@ export const generateRssFeed = async (filter) => {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.mkdirSync("./public/feeds", { recursive: true });
|
fs.mkdirSync("./public/feed", { recursive: true });
|
||||||
|
|
||||||
fs.writeFileSync(`./public/feeds/${feedTitle}-feed.xml`, feed.rss2());
|
fs.writeFileSync(`./public/feed/${feedTitle}-feed.xml`, feed.rss2());
|
||||||
|
|
||||||
fs.writeFileSync(`./public/feeds/${feedTitle}-atom.xml`, feed.atom1());
|
fs.writeFileSync(`./public/feed/${feedTitle}-atom.xml`, feed.atom1());
|
||||||
|
|
||||||
fs.writeFileSync(`./public/feeds/${feedTitle}-feed.json`, feed.json1());
|
fs.writeFileSync(`./public/feed/${feedTitle}-feed.json`, feed.json1());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -185,6 +189,6 @@ export const generatePodcastFeeds = async () => {
|
||||||
|
|
||||||
console.log(feed.rss2())
|
console.log(feed.rss2())
|
||||||
|
|
||||||
fs.writeFileSync(`./public/feeds/${series.attributes.Slug}.xml`, feed.rss2());
|
fs.writeFileSync(`./public/feed/${series.attributes.Slug}.xml`, feed.rss2());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import "../components/main"
|
||||||
import getConfig from 'next/config'
|
import getConfig from 'next/config'
|
||||||
import Layout from "../components/main"
|
import Layout from "../components/main"
|
||||||
import StoryPager from "../components/storypager"
|
import StoryPager from "../components/storypager"
|
||||||
import { getAllPosts } from "../data/external/cms";
|
import { getAllPosts, getProjectDetails } from "../data/external/cms";
|
||||||
//import { popStoryPager } from "../data/external/cms"
|
//import { popStoryPager } from "../data/external/cms"
|
||||||
|
|
||||||
export async function getServerSideProps(context) {
|
export async function getServerSideProps(context) {
|
||||||
|
|
@ -14,7 +14,9 @@ export async function getServerSideProps(context) {
|
||||||
|
|
||||||
const { serverRuntimeConfig, publicRuntimeConfig } = getConfig()
|
const { serverRuntimeConfig, publicRuntimeConfig } = getConfig()
|
||||||
|
|
||||||
const articles = await getAllPosts('tech-and-disability', page, 5)
|
const project = await getProjectDetails('tech-and-disability')
|
||||||
|
|
||||||
|
const articles = await getAllPosts(project.data[0].attributes.tags, page, 5)
|
||||||
|
|
||||||
const secres = await fetch(serverRuntimeConfig.base_path + `/api/sections`)
|
const secres = await fetch(serverRuntimeConfig.base_path + `/api/sections`)
|
||||||
const secdata = await secres.json()
|
const secdata = await secres.json()
|
||||||
|
|
@ -22,15 +24,16 @@ export async function getServerSideProps(context) {
|
||||||
const pagedata = {'title': 'Tech and Disability'}
|
const pagedata = {'title': 'Tech and Disability'}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: { articles, sections : secdata, pagedata }, // will be passed to the page component as props
|
props: { articles, sections : secdata, pagedata, project }, // will be passed to the page component as props
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function News({ articles, sections, pagedata }) {
|
function Project({ articles, sections, pagedata, project }) {
|
||||||
return <Layout sections={sections} pagedata={pagedata}>
|
return <Layout sections={sections} pagedata={pagedata}>
|
||||||
<h1>Tech and Disability</h1>
|
<h1>{project.data[0].attributes.Title}</h1>
|
||||||
|
<div dangerouslySetInnerHTML={{ __html: project.data[0].attributes.Description }}></div>
|
||||||
<StoryPager storydata={articles} />
|
<StoryPager storydata={articles} />
|
||||||
</Layout>
|
</Layout>
|
||||||
}
|
}
|
||||||
|
|
||||||
export default News
|
export default Project
|
||||||
Loading…
Reference in a new issue