1
0
Fork 0

wip(org): Make prebuild scripts more robust

This commit is contained in:
Joost De Cock 2022-06-08 16:31:03 +02:00
parent c194ea30c2
commit 1c9be8152f
2 changed files with 18 additions and 12 deletions

View file

@ -11,13 +11,20 @@ export const prebuildPatrons = async(site) => {
console.log() console.log()
console.log(`Prebuilding patron list for freesewing.${site}`) console.log(`Prebuilding patron list for freesewing.${site}`)
const patrons = await axios.get('https://backend.freesewing.org/patrons') let patrons
if (patrons?.data) { try {
const list = [ patrons = await axios.get('https://backend.freesewing.org/patrons')
}
catch (err) {
console.log(`⚠️ Failed to load patron list`)
}
const list = patrons?.data
? [
...patrons.data['2'].map(p => ({hande: p.handle, username: p.username, img: p.pictureUris.s })), ...patrons.data['2'].map(p => ({hande: p.handle, username: p.username, img: p.pictureUris.s })),
...patrons.data['4'].map(p => ({hande: p.handle, username: p.username, img: p.pictureUris.s })), ...patrons.data['4'].map(p => ({hande: p.handle, username: p.username, img: p.pictureUris.s })),
...patrons.data['8'].map(p => ({hande: p.handle, username: p.username, img: p.pictureUris.s })), ...patrons.data['8'].map(p => ({hande: p.handle, username: p.username, img: p.pictureUris.s })),
] ] : []
// Write to json // Write to json
fs.writeFileSync( fs.writeFileSync(
@ -25,5 +32,4 @@ export const prebuildPatrons = async(site) => {
`export default ${JSON.stringify(list, null ,2)}` `export default ${JSON.stringify(list, null ,2)}`
) )
} }
}

View file

@ -43,10 +43,10 @@ export const getPosts = async (type, site, lang) => {
res = await axios.get(buildUrl(type, site, lang)) res = await axios.get(buildUrl(type, site, lang))
} }
catch (err) { catch (err) {
console.log(err) console.log(`⚠️ Failed to load ${type} posts [${lang}]`)
} }
const posts = {} const posts = {}
for (const post of res.data) { for (const post of res?.data || []) {
const intro = await postIntro(`---\n---\n\n${post.body}`) const intro = await postIntro(`---\n---\n\n${post.body}`)
posts[post.slug] = { ...post, intro: intro.data.intro } posts[post.slug] = { ...post, intro: intro.data.intro }
} }