forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanifest-json.js
52 lines (49 loc) · 1.79 KB
/
manifest-json.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import fs from 'fs'
import path from 'path'
import { defaultCacheControl } from './cache-control.js'
const ICONS = [
'./assets/images/site/apple-touch-icon-57x57.png',
'./assets/images/site/apple-touch-icon-60x60.png',
'./assets/images/site/apple-touch-icon-72x72.png',
'./assets/images/site/apple-touch-icon-76x76.png',
'./assets/images/site/apple-touch-icon-114x114.png',
'./assets/images/site/apple-touch-icon-120x120.png',
'./assets/images/site/apple-touch-icon-144x144.png',
'./assets/images/site/apple-touch-icon-152x152.png',
'./assets/images/site/apple-touch-icon-180x180.png',
'./assets/images/site/apple-touch-icon-192x192.png',
'./assets/images/site/apple-touch-icon-512x512.png',
]
export default async function manifestJson(req, res) {
// This is modelled after https://github.com/manifest.json
const manifest = {
// In the future we might want to have a different manifest for each
// language. Particularly, the `name` property.
// But as of May 2023, this is overkill because all translations's
// home page refer to the name of the site as "GitHub Docs".
// For example, on https://docs.github.com/ja the `<title>`
// is "GitHub Docs".
name: 'GitHub Docs',
short_name: 'GitHub Docs',
start_url: '/',
display: 'standalone',
icons: [],
}
for (const icon of ICONS) {
for (const sizes of path.basename(icon).match(/\d+x\d+/g)) {
const stats = fs.statSync(icon)
const split = icon.slice(1).split(path.sep)
const hash = `${stats.size}`
split.splice(2, 0, `cb-${hash}`)
const src = split.join('/')
const type = path.extname(icon) === '.png' ? 'image/png' : undefined
manifest.icons.push({
sizes,
src,
type,
})
}
}
defaultCacheControl(res)
res.json(manifest)
}