Skip to content

Instantly share code, notes, and snippets.

@csszen
Last active May 17, 2021 03:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csszen/0645fc7871a20d13036c4ff00140a109 to your computer and use it in GitHub Desktop.
Save csszen/0645fc7871a20d13036c4ff00140a109 to your computer and use it in GitHub Desktop.
const fetch = require('node-fetch')
const gistIds = [
'221',
'218',
'214',
'213',
'209',
'207',
'203',
'201',
'198',
'193',
'184',
'181',
'179',
'177',
'176',
'173',
'171',
'159',
'153',
'152',
'151',
'145',
'143',
'142',
'139',
'137',
'135',
'130',
'127',
'122',
'120',
'118',
'113',
'111',
'107',
'105',
'104',
'103',
'102',
'101',
'099',
'097',
'089',
'082',
'075',
'074',
'071',
'070',
'069',
'067',
'066',
'059',
'057',
'056',
'054',
'048',
'046',
'045',
'033',
'031',
'027',
'023',
'020',
'014',
'005',
'004',
'003',
'001',
]
async function collectGists () {
gistIds.forEach(collectGist)
}
collectGists()
async function collectGist (id: string) {
try {
const pageOrigin = 'http://csszengarden.com'
const cssUrl = `${pageOrigin}/${id}/${id}.css`
const css = await (await fetch(cssUrl)).text()
const manifest = readManifestInCss(css)
const description = `css Zen Garden submission ${id} - '${manifest.name}', by ${manifest.author}, ${manifest.contact}`
await createGist(description, {
['manifest.json']: {
filename: 'manifest.json',
content: JSON.stringify(manifest, null, 2),
},
['theme.css']: {
filename: 'theme.css',
content: css,
},
})
console.info('collected:', description)
} catch (error) {
console.error('failed', id)
}
}
function readManifestInCss (css: string) {
const line = css.split('\n')[0]
const [name = '', author = '', contact = ''] = (line.split('-')[1] || '').split(',')
return {
name: name.trim().replace('\'', '').replace('\'', ''),
author: author.replace('by', '').trim(),
contact: contact.replace('*/', '').trim(),
}
}
async function createGist (description: string, files: Record<string, {
filename: string,
content: string,
}>) {
fetch('https://api.github.com/gists', {
method: 'POST',
headers: {
Accept: 'application/vnd.github.v3+json',
Authorization: `token ${process.env.GIST_TOKEN}`,
},
body: JSON.stringify({
description,
files,
public: false,
}),
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment