Skip to content

Commit

Permalink
feat: disable source only in CloudFlare
Browse files Browse the repository at this point in the history
  • Loading branch information
ourongxing committed Jan 19, 2025
1 parent b3ec041 commit b99a632
Show file tree
Hide file tree
Showing 10 changed files with 775 additions and 362 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
},
"homepage": "https://github.com/ourongxing/newsnow",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"dev": "npm run presource && vite dev",
"build": "npm run presource && vite build",
"lint": "eslint",
"source": "tsx ./scripts/favicon.ts && tsx ./scripts/pinyin.ts",
"presource": "tsx ./scripts/favicon.ts && tsx ./scripts/source.ts",
"start": "node --env-file .env.server dist/output/server/index.mjs",
"preview": "cross-env CF_PAGES=1 npm run build && wrangler pages dev dist/output/public",
"deploy": "cross-env CF_PAGES=1 npm run build && wrangler pages deploy dist/output/public",
Expand Down
4 changes: 2 additions & 2 deletions scripts/favicon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url"
import { join } from "node:path"
import { Buffer } from "node:buffer"
import { consola } from "consola"
import { originSources } from "../shared/sources"
import { originSources } from "../shared/pre-sources"

const projectDir = fileURLToPath(new URL("..", import.meta.url))
const iconsDir = join(projectDir, "public", "icons")
Expand All @@ -29,7 +29,7 @@ async function main() {
try {
const icon = join(iconsDir, `${id}.png`)
if (fs.existsSync(icon)) {
consola.info(`${id}: icon exists. skip.`)
// consola.info(`${id}: icon exists. skip.`)
return
}
if (!source.home) return
Expand Down
13 changes: 0 additions & 13 deletions scripts/pinyin.ts

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/refresh.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sources } from "../shared/sources"
import sources from "../shared/sources.json"

Promise.all(Object.keys(sources).map(id =>
fetch(`https://newsnow.busiyi.world/api/s?id=${id}`),
Expand Down
27 changes: 27 additions & 0 deletions scripts/source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { writeFileSync } from "node:fs"
import { join } from "node:path"
import { pinyin } from "@napi-rs/pinyin"
import { consola } from "consola"
import { projectDir } from "../shared/dir"
import { genSources } from "../shared/pre-sources"

const sources = genSources()
try {
const pinyinMap = Object.fromEntries(Object.entries(sources)
.filter(([, v]) => !v.redirect)
.map(([k, v]) => {
return [k, pinyin(v.title ? `${v.name}-${v.title}` : v.name).join("")]
}))

writeFileSync(join(projectDir, "./shared/pinyin.json"), JSON.stringify(pinyinMap, undefined, 2))
consola.info("Generated pinyin.json")
} catch {
consola.error("Failed to generate pinyin.json")
}

try {
writeFileSync(join(projectDir, "./shared/sources.json"), JSON.stringify(Object.fromEntries(Object.entries(sources)), undefined, 2))
consola.info("Generated sources.json")
} catch {
consola.error("Failed to generate sources.json")
}
7 changes: 5 additions & 2 deletions shared/pinyin.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
"wallstreetcn-quick": "huaerjiejianwen-shishikuaixun",
"wallstreetcn-news": "huaerjiejianwen-zuixinzixun",
"wallstreetcn-hot": "huaerjiejianwen-zuirewenzhang",
"36kr-quick": "36ke-kuaixun",
"douyin": "douyin",
"tieba": "baidutieba-reyi",
"toutiao": "jinritoutiao",
"ithome": "ITzhijia",
"thepaper": "pengpaixinwen-rebang",
"sputniknewscn": "weixingtongxunshe",
"cankaoxiaoxi": "cankaoxiaoxi",
"cls-telegraph": "cailianshe-dianbao",
"cls-depth": "cailianshe-shendu",
Expand All @@ -25,9 +27,10 @@
"producthunt": "Product Hunt",
"github-trending-today": "Github-Today",
"bilibili-hot-search": "bilibili-resou",
"kuaishou": "kuaishou",
"kaopu": "kaopuxinwen",
"jin10": "jinshishuju",
"baidu": "baiduresou",
"linuxdo-latest": "Linux DO-zuixin",
"linuxdo-hot": "Linux DO-remen"
"linuxdo-latest": "LINUX DO-zuixin",
"linuxdo-hot": "LINUX DO-jinrizuire"
}
Loading

0 comments on commit b99a632

Please sign in to comment.