Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/routes/zjnu/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '浙江师范大学',
url: 'www.zjnu.edu.cn',
lang: 'zh-CN',
};
62 changes: 62 additions & 0 deletions lib/routes/zjnu/news/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { load } from 'cheerio';

import type { Route } from '@/types';
import cache from '@/utils/cache';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';

const host = 'https://news.zjnu.edu.cn';

export const route: Route = {
path: '/news',
categories: ['university'],
example: '/zjnu/news',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '浙师要闻',
maintainers: ['gushen610140'],
handler,
};

async function handler() {
const response = await ofetch(`${host}/8449/list.htm`);
const $ = load(response);

const list = $('ul.wp_article_list>li.list_item')
.toArray()
.map((item) => {
const $item = $(item);
const a = $item.find('a').first();
return {
title: a.text(),
link: `${host}${a.attr('href')}`,
description: '',
pubDate: timezone(parseDate($item.find('div.ex_fields>span.Article_PublishDate').first().text(), 'YYYY-MM-DD'), 8),
Comment on lines +37 to +42

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you show me an example of the page structure containing multiple a or div.ex_fields>span.Article_PublishDate elements within each ul.wp_article_list>li.list_item that first() is required to select the correct element?

author: '浙江师范大学',
};
});

const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const detail = await ofetch(item.link);
const $detail = load(detail);
return { ...item, description: $detail('div.Article_Content').first().html() ?? '' };

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you show me an example of the page structure containing multiple div.Article_Content elements that first() is required to select the correct element?

})
)
);

return {
title: '浙师要闻',
link: `${host}/8449/list.htm`,
item: items,
};
}