forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add route of ζζ (DIYgod#16831)
* feat(route): add route of ζζ * fix: solve review * fix: solve review * fix: solve review * fix: solve review
- Loading branch information
Showing
3 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Data, DataItem, Route } from '@/types'; | ||
import cache from '@/utils/cache'; | ||
import got from '@/utils/got'; | ||
import { load } from 'cheerio'; | ||
|
||
export const route: Route = { | ||
path: '/', | ||
categories: ['reading'], | ||
example: '/yilinzazhi', | ||
radar: [ | ||
{ | ||
source: ['www.yilinzazhi.com'], | ||
target: '/', | ||
}, | ||
], | ||
name: 'ζη« ε葨', | ||
maintainers: ['g0ngjie'], | ||
handler, | ||
url: 'www.yilinzazhi.com', | ||
}; | ||
|
||
async function handler(): Promise<Data> { | ||
const baseUrl = 'https://www.yilinzazhi.com/'; | ||
const response = await got(baseUrl); | ||
const $ = load(response.data); | ||
const contents: DataItem[] = $('section.content') | ||
.find('li') | ||
.map((_, target) => { | ||
const li = $(target); | ||
|
||
const aTag = li.find('a'); | ||
const title = aTag.text(); | ||
const link = baseUrl + aTag.attr('href'); | ||
|
||
return { | ||
title, | ||
link, | ||
description: '', | ||
}; | ||
}) | ||
.toArray(); | ||
|
||
const items = (await Promise.all( | ||
contents.map((content) => | ||
cache.tryGet(content.link!, async () => { | ||
const childRes = await got(content.link); | ||
const $$ = load(childRes.data); | ||
content.description = $$('.maglistbox').html()!; | ||
return content; | ||
}) | ||
) | ||
)) as DataItem[]; | ||
return { | ||
title: 'ζζζεΏη½', | ||
link: baseUrl, | ||
item: items, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { Data, DataItem, Route } from '@/types'; | ||
import cache from '@/utils/cache'; | ||
import got from '@/utils/got'; | ||
import { load } from 'cheerio'; | ||
import dayjs from 'dayjs'; | ||
|
||
export const route: Route = { | ||
path: '/latest', | ||
categories: ['reading'], | ||
example: '/yilinzazhi/latest', | ||
radar: [ | ||
{ | ||
source: ['www.yilinzazhi.com'], | ||
target: '/', | ||
}, | ||
], | ||
name: 'θΏζζη« ζ±ζ»', | ||
maintainers: ['g0ngjie'], | ||
handler, | ||
url: 'www.yilinzazhi.com', | ||
description: 'ζθΏδΈζηζη« ζ±ζ»', | ||
}; | ||
|
||
type Stage = { | ||
link: string; | ||
title: string; | ||
}; | ||
|
||
type Catalog = { | ||
title: string; | ||
tables: Data[]; | ||
}; | ||
|
||
async function handler(): Promise<Data> { | ||
const baseUrl = 'https://www.yilinzazhi.com/'; | ||
const response = await got(baseUrl); | ||
const $ = load(response.data); | ||
|
||
const currentYear = dayjs().year(); | ||
const yearSection = $('.year-section') | ||
.toArray() | ||
.find((el) => | ||
$(el) | ||
.find('.year-title') | ||
.text() | ||
.includes(currentYear + '') | ||
); | ||
|
||
const stage = $(yearSection!) | ||
.find('a') | ||
.map<typeof yearSection, Stage>(function () { | ||
const aTag = $(this); | ||
const link = baseUrl + aTag.attr('href'); | ||
const title = aTag.text(); | ||
return { link, title }; | ||
}) | ||
.toArray()[0]; | ||
|
||
const catalogs = (await cache.tryGet(stage.link, async () => { | ||
const stageRes = await got(stage.link); | ||
const $$ = load(stageRes.data); | ||
const catalogsEl = $$('.maglistbox dl').toArray(); | ||
const children = catalogsEl.map<Catalog>((catalog) => { | ||
const title = $$(catalog).find('dt span').text(); | ||
const tables = $$(catalog) | ||
.find('a') | ||
.toArray() | ||
.map<Data>((aTag) => { | ||
const href = $$(aTag).attr('href')!; | ||
const yearType = currentYear + href.substring(4, 5); | ||
return { | ||
title: $$(aTag).text(), | ||
link: `${baseUrl}${currentYear}/yl${yearType}/${href}`, | ||
}; | ||
}); | ||
return { title, tables }; | ||
}); | ||
return children; | ||
})) as Catalog[]; | ||
|
||
const contents: Data[] = catalogs.flatMap((catalog) => catalog.tables); | ||
|
||
const items = (await Promise.all( | ||
contents.map( | ||
async (target) => | ||
await cache.tryGet(target.link!, async () => { | ||
const detailRes = await got(target.link); | ||
const $$ = load(detailRes.data); | ||
const detailContainer = $$('.blkContainerSblk.collectionContainer'); | ||
|
||
target.description = detailContainer.html()!; | ||
|
||
return target; | ||
}) | ||
) | ||
)) as DataItem[]; | ||
|
||
return { | ||
title: 'ζζ - θΏζζη« ζ±ζ»', | ||
link: stage.link, | ||
item: items, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { Namespace } from '@/types'; | ||
|
||
export const namespace: Namespace = { | ||
name: 'ζζζεΏ', | ||
url: 'www.yilinzazhi.com', | ||
categories: ['reading'], | ||
description: '', | ||
}; |