chore: import upstream snapshot with attribution
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
Build Chrome Extension / build (push) Has been cancelled
Trigger Website Rebuild (Docs Updated) / dispatch (push) Has been cancelled
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
Build Chrome Extension / build (push) Has been cancelled
Trigger Website Rebuild (Docs Updated) / dispatch (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { cli, Strategy } from '@jackwener/opencli/registry';
|
||||
import { fetchLinuxDoJson } from './feed.js';
|
||||
function toLocalTime(utcStr) {
|
||||
if (!utcStr)
|
||||
return '';
|
||||
const date = new Date(utcStr);
|
||||
return Number.isNaN(date.getTime()) ? utcStr : date.toLocaleString();
|
||||
}
|
||||
function strip(html) {
|
||||
return (html || '')
|
||||
.replace(/<br\s*\/?>/gi, ' ')
|
||||
.replace(/<\/(p|div|li|blockquote|h[1-6])>/gi, ' ')
|
||||
.replace(/<[^>]+>/g, '')
|
||||
.replace(/ /g, ' ')
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/&#(?:(\d+)|x([0-9a-fA-F]+));/g, (_, dec, hex) => {
|
||||
try {
|
||||
return String.fromCodePoint(dec !== undefined ? Number(dec) : parseInt(hex, 16));
|
||||
}
|
||||
catch {
|
||||
return '';
|
||||
}
|
||||
})
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim();
|
||||
}
|
||||
cli({
|
||||
site: 'linux-do',
|
||||
name: 'topic',
|
||||
access: 'read',
|
||||
description: 'linux.do 帖子首页摘要和回复(首屏)',
|
||||
domain: 'linux.do',
|
||||
strategy: Strategy.COOKIE,
|
||||
browser: true,
|
||||
args: [
|
||||
{ name: 'id', type: 'int', required: true, positional: true, help: 'Topic ID' },
|
||||
{ name: 'limit', type: 'int', default: 20, help: 'Number of posts' },
|
||||
],
|
||||
columns: ['author', 'content', 'likes', 'created_at'],
|
||||
func: async (page, kwargs) => {
|
||||
const data = await fetchLinuxDoJson(page, `/t/${kwargs.id}.json`);
|
||||
const posts = (data?.post_stream?.posts || []);
|
||||
return posts.slice(0, kwargs.limit).map((p) => ({
|
||||
author: p.username,
|
||||
content: strip(p.cooked).slice(0, 200),
|
||||
likes: p.like_count,
|
||||
created_at: toLocalTime(p.created_at),
|
||||
}));
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user