Skip to content

Commit

Permalink
Merge pull request #7 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] committed Jun 3, 2024
2 parents e3dc98b + 7175ab0 commit cc254ee
Show file tree
Hide file tree
Showing 6 changed files with 287 additions and 183 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ jobs:
- run: pnpm i
- name: Build radar and maintainer
run: npm run build
- name: Upload assets
uses: actions/upload-artifact@v4
with:
name: generated-assets-${{ matrix.node-version }}
path: assets/build/

automerge:
if: github.triggering_actor == 'dependabot[bot]' && github.event_name == 'pull_request'
Expand Down
39 changes: 28 additions & 11 deletions lib/routes/apnews/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,33 @@ export function fetchArticle(item) {
return cache.tryGet(item.link, async () => {
const data = await ofetch(item.link);
const $ = load(data);
const ldjson = JSON.parse($('#link-ld-json').text())[0];
$('div.Enhancement').remove();
return {
pubDate: parseDate(ldjson.datePublished),
updated: parseDate(ldjson.dateModified),
description: $('div.RichTextStoryBody').html(),
category: [`section:${$("meta[property='article:section']").attr('content')}`, ...ldjson.keywords],
guid: $("meta[name='brightspot.contentId']").attr('content'),
author: ldjson.author,
...item,
};
const rawLdjson = JSON.parse($('#link-ld-json').text());
let ldjson;
if (Array.isArray(rawLdjson)) {
// Regular
ldjson = rawLdjson[0];

$('div.Enhancement').remove();
return {
pubDate: parseDate(ldjson.datePublished),
updated: parseDate(ldjson.dateModified),
description: $('div.RichTextStoryBody').html(),
category: [`section:${$("meta[property='article:section']").attr('content')}`, ...ldjson.keywords],
guid: $("meta[name='brightspot.contentId']").attr('content'),
author: ldjson.author,
...item,
};
} else {
// Live
ldjson = rawLdjson;

return {
category: ldjson.keywords,
pubDate: parseDate(ldjson.coverageStartTime),
description: ldjson.description,
guid: $("meta[name='brightspot.contentId']").attr('content'),
...item,
};
}
});
}
58 changes: 58 additions & 0 deletions lib/routes/bugzilla/bug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { load } from 'cheerio';
import { Context } from 'hono';
import InvalidParameterError from '@/errors/types/invalid-parameter';
import { Data, DataItem, Route } from '@/types';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';

const INSTANCES = new Map([
['apache', 'bz.apache.org/bugzilla'],
['apache.ooo', 'bz.apache.org/ooo'], // Apache OpenOffice
['apache.SpamAssassin', 'bz.apache.org/SpamAssassin'],
['mozilla', 'bugzilla.mozilla.org'],
['webkit', 'bugs.webkit.org'],
]);

async function handler(ctx: Context): Promise<Data> {
const { site, bugId } = ctx.req.param();
if (!INSTANCES.has(site)) {
throw new InvalidParameterError(`unknown site: ${site}`);
}
const link = `https://${INSTANCES.get(site)}/show_bug.cgi?id=${bugId}`;
const $ = load(await ofetch(`${link}&ctype=xml`));
const items = $('long_desc').map((index, rawItem) => {
const $ = load(rawItem, null, false);
return {
title: `comment #${$('commentid').text()}`,
link: `${link}#c${index}`,
description: $('thetext').text(),
pubDate: parseDate($('bug_when').text()),
author: $('who').attr('name'),
} as DataItem;
});
return { title: $('short_desc').text(), link, item: items.toArray() };
}

function markdownFrom(instances: Map<string, string>, separator: string = ', '): string {
return [...instances.entries()].map(([k, v]) => `[\`${k}\`](https://${v})`).join(separator);
}

export const route: Route = {
path: '/bug/:site/:bugId',
name: 'bugs',
maintainers: ['FranklinYu'],
handler,
example: '/bug/webkit/251528',
parameters: {
site: 'site identifier',
bugId: 'numeric identifier of the bug in the site',
},
description: `Supported site identifiers: ${markdownFrom(INSTANCES)}.`,
categories: ['programming'],

// Radar is infeasible, because it needs access to URL parameters.
zh: {
name: 'bugs',
description: `支持的站点标识符:${markdownFrom(INSTANCES, '、')}。`,
},
};
11 changes: 11 additions & 0 deletions lib/routes/bugzilla/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'Bugzilla',
url: 'bugzilla.org',
description: 'Bugzilla instances hosted by organizations.',
zh: {
name: 'Bugzilla',
description: '各组织自建的Bugzilla实例。',
},
};
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@
"dependencies": {
"@hono/node-server": "1.11.2",
"@hono/swagger-ui": "0.2.2",
"@hono/zod-openapi": "0.14.0",
"@hono/zod-openapi": "0.14.1",
"@notionhq/client": "2.2.15",
"@postlight/parser": "2.2.3",
"@sentry/node": "8.7.0",
"@tonyrl/rand-user-agent": "2.0.65",
"@tonyrl/rand-user-agent": "2.0.66",
"aes-js": "3.1.2",
"art-template": "4.13.2",
"bbcodejs": "0.0.4",
"cheerio": "1.0.0-rc.12",
"chrono-node": "2.7.5",
"chrono-node": "2.7.6",
"city-timezones": "1.2.1",
"cross-env": "7.0.3",
"crypto-js": "4.2.0",
Expand Down Expand Up @@ -114,10 +114,10 @@
"telegram": "2.21.2",
"tiny-async-pool": "2.1.0",
"title": "3.5.3",
"tldts": "6.1.23",
"tldts": "6.1.24",
"tosource": "2.0.0-alpha.3",
"tough-cookie": "4.1.4",
"tsx": "4.11.0",
"tsx": "4.11.2",
"twitter-api-v2": "1.17.0",
"undici": "6.18.2",
"uuid": "9.0.1",
Expand Down Expand Up @@ -147,7 +147,7 @@
"@types/mailparser": "3.4.4",
"@types/markdown-it": "14.1.1",
"@types/module-alias": "2.0.4",
"@types/node": "20.12.13",
"@types/node": "20.14.0",
"@types/sanitize-html": "2.11.0",
"@types/supertest": "6.0.2",
"@types/tiny-async-pool": "2.0.3",
Expand All @@ -171,8 +171,8 @@
"js-beautify": "1.15.1",
"lint-staged": "15.2.5",
"mockdate": "3.0.5",
"msw": "2.3.0",
"prettier": "3.2.5",
"msw": "2.3.1",
"prettier": "3.3.0",
"remark-parse": "11.0.0",
"supertest": "7.0.0",
"typescript": "5.4.5",
Expand Down
Loading

0 comments on commit cc254ee

Please sign in to comment.