Skip to content

Commit 0f5677e

Browse files
committed
Update UI
1 parent c0e9eff commit 0f5677e

21 files changed

Lines changed: 1394 additions & 1189 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ coverage
3737
/public
3838
/src/api/version.ts
3939
/dist
40+
/AGENTS.md

bin/build-all.js

Lines changed: 74 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import { resolve } from 'path'
44
import { cwd } from './common.js'
55
import fs from 'fs/promises'
66

7+
const REDIRECT_TEMPLATE = (target) => `<!DOCTYPE html><html><head><meta charset="utf-8"><meta http-equiv="refresh" content="0;url=${target}"><link rel="canonical" href="${target}"></head><body></body></html>`
8+
79
async function buildVideoPages () {
810
const { videos } = data
911
const h = process.env.HOST
1012

11-
// Build videos index page
1213
const videosIndexFrom = resolve(cwd, 'src/views/videos.pug')
1314
const videosIndexTo = resolve(cwd, 'public/videos/index.html')
1415
await fs.mkdir(resolve(cwd, 'public/videos'), { recursive: true })
@@ -26,7 +27,6 @@ async function buildVideoPages () {
2627

2728
console.log('✅ Built videos index page')
2829

29-
// Build individual video pages
3030
for (const video of videos) {
3131
const videoDir = resolve(cwd, `public/videos/${video.videoSlug}`)
3232
await fs.mkdir(videoDir, { recursive: true })
@@ -52,83 +52,89 @@ async function buildVideoPages () {
5252
async function main () {
5353
const { langs, pages } = data
5454
const from = resolve(cwd, 'src/views/index.pug')
55+
const h = process.env.HOST
56+
5557
for (const item of langs) {
56-
const { id, langCode, lang } = item
57-
const n = id === 'en_us' ? 'index.html' : 'index-' + id + '.html'
58-
const to = resolve(cwd, 'public/' + n)
59-
const h = process.env.HOST
58+
const { id, slug, langCode, lang } = item
6059
const view = 'index'
61-
await buildPug(from, to, {
62-
...data,
63-
langCode,
64-
lang,
65-
desc: lang.lang.desc,
66-
url: h,
67-
cssUrl: view + '.bundle.css',
68-
jsUrl: view + '.bundle.js'
69-
})
60+
61+
if (id === 'en_us') {
62+
// English → public/index.html
63+
const to = resolve(cwd, 'public/index.html')
64+
await buildPug(from, to, {
65+
...data,
66+
langCode,
67+
lang,
68+
desc: lang.lang.desc,
69+
url: h,
70+
cssUrl: view + '.bundle.css',
71+
jsUrl: view + '.bundle.js'
72+
})
73+
} else {
74+
// Other locales → public/{slug}/index.html + public/index-{id}.html redirect
75+
const dir = resolve(cwd, 'public/' + slug)
76+
await fs.mkdir(dir, { recursive: true })
77+
78+
const to = resolve(dir, 'index.html')
79+
await buildPug(from, to, {
80+
...data,
81+
langCode,
82+
lang,
83+
desc: lang.lang.desc,
84+
url: h + '/' + slug + '/',
85+
cssUrl: '/' + view + '.bundle.css',
86+
jsUrl: '/' + view + '.bundle.js'
87+
})
88+
89+
// Build redirect page at old path
90+
const redirectFrom = resolve(cwd, 'public/index-' + id + '.html')
91+
const target = h + '/' + slug + '/'
92+
await fs.writeFile(redirectFrom, REDIRECT_TEMPLATE(target))
93+
}
7094
}
71-
// const installSrc = [
72-
// 'linux-arm64.tar.gz',
73-
// 'linux-arm64.deb',
74-
// 'linux-aarch64.rpm',
75-
// 'linux-arm64.AppImage',
76-
// 'linux-armv7l.tar.gz',
77-
// 'linux-armv7l.deb',
78-
// 'linux-armv7l.rpm',
79-
// 'linux-armv7l.AppImage',
80-
// 'linux-x64.tar.gz',
81-
// 'linux-x64.deb',
82-
// 'linux-x86_64.AppImage',
83-
// 'linux-x86_64.rpm',
84-
// 'linux-amd64.snap',
85-
// 'mac-arm64.dmg',
86-
// 'mac-x64.dmg',
87-
// 'win-x64.tar.gz',
88-
// 'win-x64.appx',
89-
// 'win-x64-installer.exe',
90-
// 'win-x64-loose.tar.gz',
91-
// 'win-x64-portable.tar.gz',
92-
// 'win7.tar.gz'
93-
// ]
94-
95-
// Add this after writing version.html:
95+
9696
const { version } = data
9797
await fs.writeFile(resolve(cwd, 'public/version.html'), version)
9898

99-
// Create version-specific files
100-
// for (const src of installSrc) {
101-
// const fileName = src.replace(/\./g, '-')
102-
// await fs.writeFile(
103-
// resolve(cwd, `public/version-${fileName}.html`),
104-
// version
105-
// )
106-
// }
99+
// Build static pages: sponsor-electerm at /sponsor-electerm/index.html
100+
// with redirect at /sponsor-electerm.html
107101
for (const item of pages) {
108102
const { langCode, lang } = langs[2]
109103
const f = resolve(cwd, 'src/views/' + item + '.pug')
110-
const to = item === 'deb'
111-
? resolve(cwd, 'public/deb/index.html')
112-
: resolve(cwd, 'public/' + item + '.html')
113-
const h = process.env.HOST
114-
const cssUrl = item === 'deb'
115-
? '/index.bundle.css'
116-
: 'index.bundle.css'
117-
const jsUrl = item === 'deb'
118-
? '/index.bundle.js'
119-
: 'index.bundle.js'
120-
await buildPug(f, to, {
121-
...data,
122-
langCode,
123-
lang,
124-
desc: lang.lang.desc,
125-
url: h,
126-
cssUrl,
127-
jsUrl
128-
})
104+
105+
if (item === 'deb') {
106+
const debDir = resolve(cwd, 'public/deb')
107+
await fs.mkdir(debDir, { recursive: true })
108+
await buildPug(f, resolve(debDir, 'index.html'), {
109+
...data,
110+
langCode,
111+
lang,
112+
desc: lang.lang.desc,
113+
url: h,
114+
cssUrl: '/index.bundle.css',
115+
jsUrl: '/index.bundle.js'
116+
})
117+
} else {
118+
// Build at /{item}/index.html
119+
const dir = resolve(cwd, 'public/' + item)
120+
await fs.mkdir(dir, { recursive: true })
121+
await buildPug(f, resolve(dir, 'index.html'), {
122+
...data,
123+
langCode,
124+
lang,
125+
desc: lang.lang.desc,
126+
url: h + '/' + item + '/',
127+
cssUrl: '/index.bundle.css',
128+
jsUrl: '/index.bundle.js'
129+
})
130+
131+
// Redirect from old /{item}.html
132+
const redirectFrom = resolve(cwd, 'public/' + item + '.html')
133+
const target = h + '/' + item + '/'
134+
await fs.writeFile(redirectFrom, REDIRECT_TEMPLATE(target))
135+
}
129136
}
130137

131-
// Build video pages
132138
await buildVideoPages()
133139
}
134140

bin/data.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ function convertToProperLangCode (code) {
2727
en_us: 'en-US',
2828
es_es: 'es-ES',
2929
fr_fr: 'fr',
30+
id_id: 'id',
3031
ja_jp: 'ja',
3132
ko_kr: 'ko',
33+
pl_pl: 'pl',
3234
pt_br: 'pt-BR',
3335
ru_ru: 'ru',
3436
tr_tr: 'tr',
@@ -39,6 +41,26 @@ function convertToProperLangCode (code) {
3941
return langMappings[code] || code
4042
}
4143

44+
function localeIdToSlug (id) {
45+
const slugMap = {
46+
ar_ar: 'ar',
47+
de_de: 'de',
48+
en_us: '',
49+
es_es: 'es',
50+
fr_fr: 'fr',
51+
id_id: 'id',
52+
ja_jp: 'ja',
53+
ko_kr: 'ko',
54+
pl_pl: 'pl',
55+
pt_br: 'pt-br',
56+
ru_ru: 'ru',
57+
tr_tr: 'tr',
58+
zh_cn: 'zh-cn',
59+
zh_tw: 'zh-tw'
60+
}
61+
return slugMap[id]
62+
}
63+
4264
function createLocaleData () {
4365
// languages
4466
const localeFolder = resolve(cwd, 'node_modules/@electerm/electerm-locales/dist/cjs')
@@ -55,11 +77,13 @@ function createLocaleData () {
5577
}
5678
const lang = j5.parse(fs.readFileSync(filePath, 'utf-8').replace('module.exports=exports.default=', ''))
5779
const id = fileName.replace('.js', '')
58-
const url = id === 'en_us' ? pre : pre + '/index-' + id + '.html'
80+
const slug = localeIdToSlug(id)
81+
const url = slug === '' ? pre : pre + '/' + slug + '/'
5982
prev = [
6083
...prev,
6184
{
6285
id,
86+
slug,
6387
langCode: convertToProperLangCode(id),
6488
lang,
6589
url

bin/sitemap.js

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// create sitemap
21
import fs from 'fs/promises'
32
import { createSitemap } from 'sitemaps'
43
import { cwd } from './common.js'
@@ -8,63 +7,58 @@ import data from './data.js'
87

98
const fmt = 'YYYY-MM-DD'
109

11-
async function buildPages () {
12-
const to = 'public'
13-
const from = resolve(cwd, to)
14-
const list = await fs.readdir(from)
15-
const arr = []
16-
for (const f of list) {
17-
if (f.startsWith('index-')) {
18-
const ff = resolve(from, f)
19-
const s = await fs.stat(ff)
20-
const host = data.host || 'https://electerm.html5beta.com'
21-
arr.push({
22-
loc: host + '/' + f,
23-
lastmod: dayjs(s.mtime).format(fmt),
24-
changefreq: 'weekly',
25-
priority: 0.8
26-
})
27-
}
28-
}
29-
return arr
30-
}
31-
3210
async function buildSiteMap () {
3311
const urls = []
34-
const index = resolve(
35-
cwd, 'public/index.html'
36-
)
37-
const state = await fs.stat(index)
3812
const host = data.host || 'https://electerm.html5beta.com'
13+
14+
// English index
15+
const index = resolve(cwd, 'public/index.html')
16+
const state = await fs.stat(index)
3917
urls.push({
4018
loc: host,
4119
lastmod: dayjs(state.mtime).format(fmt),
4220
changefreq: 'weekly',
4321
priority: 1
4422
})
23+
24+
// Locale pages (exclude en_us which is root)
25+
for (const item of data.langs) {
26+
if (item.slug) {
27+
const dir = resolve(cwd, 'public/' + item.slug)
28+
try {
29+
const s = await fs.stat(resolve(dir, 'index.html'))
30+
urls.push({
31+
loc: host + '/' + item.slug + '/',
32+
lastmod: dayjs(s.mtime).format(fmt),
33+
changefreq: 'weekly',
34+
priority: 0.8
35+
})
36+
} catch (e) {}
37+
}
38+
}
39+
40+
// Static pages (sponsor-electerm, etc)
4541
for (const page of data.pages) {
4642
if (page !== 'deb') {
4743
urls.push({
48-
loc: host + '/' + page + '.html',
44+
loc: host + '/' + page + '/',
4945
lastmod: dayjs(state.mtime).format(fmt),
5046
changefreq: 'weekly',
5147
priority: 1
5248
})
5349
}
5450
}
55-
const arr = await buildPages()
56-
urls.push(...arr)
5751

58-
// Add videos index page
52+
// Videos index
5953
urls.push({
6054
loc: host + '/videos',
6155
lastmod: dayjs().format(fmt),
6256
changefreq: 'weekly',
6357
priority: 0.9
6458
})
6559

66-
// Add individual video pages
67-
if (data.videos && data.videos) {
60+
// Individual video pages
61+
if (data.videos) {
6862
for (const video of data.videos) {
6963
urls.push({
7064
loc: `${host}/videos/${video.videoSlug}/`,

0 commit comments

Comments
 (0)