angrybeanie-front-end/data/external/cms.js
James Purser 25e70c36d4 Added Tech and Disability section to navigation and page
Refactored News to use the getAllPosts method in data/external/cms
2022-06-14 20:58:06 +10:00

76 lines
No EOL
1.7 KiB
JavaScript
Executable file

import getConfig from 'next/config'
export const getAllPosts = async (filter, page, limit) => {
console.log(filter + " " + page + " " + limit)
const { serverRuntimeConfig, publicRuntimeConfig } = getConfig()
const qs = require('qs')
const qVal = []
if (page == null) {
page = 0
}
if (limit == null) {
limit = 50;
}
var filters = {}
if (filter) {
filters = {
tags: {
Slug: {
$contains: filter
}
}
}
}
console.log(filter)
const qArray = {
sort: ['publishedAt:desc'],
pagination: {
page: page,
pageSize: limit
},
filters
}
const query = qs.stringify( qArray, {
encodeValuesOnly: true,
})
const res = await fetch(serverRuntimeConfig.base_path + `articles?${query}`, {
headers: new Headers({
'Authorization': serverRuntimeConfig.strapi_token,
'Content-Type': 'application/x-www-form-urlencoded'
})
})
return await res.json()
}
export const getAllPodcastSeries = async () => {
const { serverRuntimeConfig } = getConfig()
const qs = require('qs')
const query = qs.stringify({
populate: {
podcast_episodes: {
populate:['Audio']
}
}
}, {
encodeValuesOnly: true,
})
const res = await fetch(serverRuntimeConfig.base_path + `podcast-series?${query}`, {
headers: new Headers({
'Authorization': serverRuntimeConfig.strapi_token,
'Content-Type': 'application/x-www-form-urlencoded'
})
})
return await res.json()
}