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,19 +11,25 @@ export const prebuildPatrons = async(site) => {
console.log()
console.log(`Prebuilding patron list for freesewing.${site}`)
const patrons = await axios.get('https://backend.freesewing.org/patrons')
if (patrons?.data) {
const list = [
let patrons
try {
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['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 })),
]
] : []
// Write to json
fs.writeFileSync(
path.resolve('..', `freesewing.${site}`, 'prebuild', `patrons.js`),
`export default ${JSON.stringify(list, null ,2)}`
)
}
// Write to json
fs.writeFileSync(
path.resolve('..', `freesewing.${site}`, 'prebuild', `patrons.js`),
`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))
}
catch (err) {
console.log(err)
console.log(`⚠️ Failed to load ${type} posts [${lang}]`)
}
const posts = {}
for (const post of res.data) {
for (const post of res?.data || []) {
const intro = await postIntro(`---\n---\n\n${post.body}`)
posts[post.slug] = { ...post, intro: intro.data.intro }
}