Skip to content

Commit

Permalink
Merge pull request #1370 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Apr 30, 2024
2 parents fbce0af + 06fafcc commit 37c9af1
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 139 deletions.
66 changes: 66 additions & 0 deletions lib/routes/copernicium/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Route } from '@/types';
import ofetch from '@/utils/ofetch';

import cache from '@/utils/cache';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';

export const route: Route = {
path: '/:category',
categories: ['new-media'],
radar: [{ source: ['www.copernicium.tw'] }],
name: '分类',
example: '/copernicium/环球视角',
parameters: { category: '分类名' },
maintainers: ['dzx-dzx'],
handler,
};

async function handler(ctx) {
const CATEGORY_TO_ARG_MAP = new Map([
['环球视角', '4_1'],
['人文叙述', '4_3'],
['观点评论', '4_5'],
]);
if (!CATEGORY_TO_ARG_MAP.get(ctx.req.param().category)) {
throw new Error('The requested category does not exist or is not supported.');
}
const reqArgs = {
args: {
_jcp: CATEGORY_TO_ARG_MAP.get(ctx.req.param().category),
m31pageno: 1,
},
type: 0,
};
const res = await ofetch(`https://www.copernicium.tw/nr.jsp`, {
query: { _reqArgs: reqArgs },
});
const $ = load(res);
const list = $('.J_newsResultLine a.mixNewsStyleTitle')
.toArray()
.map((e) => {
e = $(e);
return {
title: e.text(),
link: e.attr('href'),
};
});
const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const detailResponse = await ofetch(item.link);
const content = load(detailResponse);
return {
pubDate: parseDate(content('span.newsInfo').text().substring(5)),
description: content('.richContent').html(),
...item,
};
})
)
);
return {
title: `日新说 - ${ctx.req.param().category}`,
link: 'https://www.copernicium.tw',
item: items,
};
}
6 changes: 6 additions & 0 deletions lib/routes/copernicium/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '日新说',
url: 'www.copernicium.tw',
};
38 changes: 20 additions & 18 deletions lib/routes/crossbell/feeds/following.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,26 @@ async function handler(ctx) {
return {
title: 'Crossbell Feeds of ' + characterId,
link: 'https://crossbell.io/',
item: response.data?.list?.map((item) => {
let link = item.note ? item.note.metadata?.content?.external_urls?.[0] || `https://crossbell.io/notes/${item.note.characterId}-${item.note.noteId}` : 'https://xchar.app/' + item.character.handle;
if (link.startsWith('https://xn--')) {
link = `https://crossbell.io/notes/${item.note?.characterId}-${item.note?.noteId}`;
}
item: response.data?.list
?.filter((item) => item.type !== 'UPDATE_CHARACTER_METADATA')
.map((item) => {
let link = item.note ? item.note.metadata?.content?.external_urls?.[0] || `https://crossbell.io/notes/${item.note.characterId}-${item.note.noteId}` : 'https://xchar.app/' + item.character.handle;
if (link.startsWith('https://xn--')) {
link = `https://crossbell.io/notes/${item.note?.characterId}-${item.note?.noteId}`;
}

return {
title: `${item.type} ${item.character && item.character.metadata?.content?.name}@${item.character && item.character.handle}`,
description: `${item.type} ${item.note && `<br>Note: ${item.note.metadata?.content?.title || item.note.metadata?.content?.content}`}${
item.character && `<br>Character: ${item.character.metadata?.content?.name}@${item.character.handle}`
}`,
link,
pubDate: item.createdAt,
updated: item.updatedAt,
author: item.note?.metadata?.content?.authors?.[0] || item.note?.character?.metadata?.content?.name || item.note?.character?.handle || item.owner,
guid: item.transactionHash + item.logIndex + item.type,
category: [...(item.note?.metadata?.content?.sources || []), ...(item.note?.metadata?.content?.tags || [])],
};
}),
return {
title: `${item.type} ${item.character && item.character.metadata?.content?.name}@${item.character && item.character.handle}`,
description: `${item.type} ${item.note && `<br>Note: ${item.note.metadata?.content?.title || item.note.metadata?.content?.content}`}${
item.character && `<br>Character: ${item.character.metadata?.content?.name}@${item.character.handle}`
}`,
link,
pubDate: item.createdAt,
updated: item.updatedAt,
author: item.note?.metadata?.content?.authors?.[0] || item.note?.character?.metadata?.content?.name || item.note?.character?.handle || item.owner,
guid: item.transactionHash + item.logIndex + item.type,
category: [...(item.note?.metadata?.content?.sources || []), ...(item.note?.metadata?.content?.tags || [])],
};
}),
};
}
32 changes: 15 additions & 17 deletions lib/routes/crossbell/notes/utils.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
export default {
getItem: (note) => {
let link = note.metadata?.content?.external_urls?.[0] ?? `https://crossbell.io/notes/${note.characterId}-${note.noteId}`;
if (link.startsWith('https://xn--')) {
link = `https://crossbell.io/notes/${note.characterId}-${note.noteId}`;
}
return {
title: note.metadata?.content?.title || '',
description: note.metadata?.content?.content,
link,
pubDate: note.metadata?.content?.publishedAt,
updated: note.metadata?.content?.updatedAt,
author: note.metadata?.content?.authors?.[0] || note.character?.metadata?.content?.name || note.character?.handle,
guid: `https://crossbell.io/notes/${note.characterId}-${note.noteId}`,
category: [...(note.metadata?.content?.sources || []), ...(note.metadata?.content?.tags || [])],
};
},
export const getItem = (note) => {
let link = note.metadata?.content?.external_urls?.[0] ?? `https://crossbell.io/notes/${note.characterId}-${note.noteId}`;
if (link.startsWith('https://xn--')) {
link = `https://crossbell.io/notes/${note.characterId}-${note.noteId}`;
}
return {
title: note.metadata?.content?.title || '',
description: note.metadata?.content?.content,
link,
pubDate: note.metadata?.content?.publishedAt,
updated: note.metadata?.content?.updatedAt,
author: note.metadata?.content?.authors?.[0] || note.character?.metadata?.content?.name || note.character?.handle,
guid: `https://crossbell.io/notes/${note.characterId}-${note.noteId}`,
category: [...(note.metadata?.content?.sources || []), ...(note.metadata?.content?.tags || [])],
};
};
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@
"tough-cookie": "4.1.4",
"tsx": "4.7.3",
"twitter-api-v2": "1.16.3",
"undici": "6.14.1",
"undici": "6.15.0",
"uuid": "9.0.1",
"winston": "3.13.0",
"xxhash-wasm": "1.0.2",
"zod": "3.23.4"
"zod": "3.23.5"
},
"devDependencies": {
"@babel/preset-env": "7.24.5",
Expand Down Expand Up @@ -153,7 +153,7 @@
"@types/title": "3.4.3",
"@types/tough-cookie": "4.0.5",
"@types/uuid": "9.0.8",
"@typescript-eslint/eslint-plugin": "7.7.1",
"@typescript-eslint/eslint-plugin": "7.8.0",
"@typescript-eslint/parser": "7.8.0",
"@vercel/nft": "0.26.4",
"@vitest/coverage-v8": "1.5.2",
Expand Down
Loading

0 comments on commit 37c9af1

Please sign in to comment.