-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
77 additions
and
155 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
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
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
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,41 @@ | ||
import { getCurrentPath } from '@/utils/helpers'; | ||
const __dirname = getCurrentPath(import.meta.url); | ||
|
||
import cache from '@/utils/cache'; | ||
import ofetch from '@/utils/ofetch'; | ||
import timezone from '@/utils/timezone'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
import { art } from '@/utils/render'; | ||
import path from 'node:path'; | ||
import MarkdownIt from 'markdown-it'; | ||
const md = MarkdownIt({ | ||
html: true, | ||
}); | ||
|
||
export const rootUrl = 'https://utgd.net'; | ||
export const apiRootUrl = 'https://api.utgd.net'; | ||
|
||
export const parseResult = (results, limit) => | ||
results.slice(0, limit).map((item) => ({ | ||
id: item.id, | ||
title: item.title, | ||
link: `${rootUrl}/article/${item.id}`, | ||
author: item.article_author_displayname, | ||
pubDate: timezone(parseDate(item.article_published_time), +8), | ||
category: item.article_category.map((c) => c.category_name), | ||
})); | ||
|
||
export const parseArticle = (item) => | ||
cache.tryGet(`untag-${item.id}`, async () => { | ||
const data = await ofetch(`${apiRootUrl}/api/v2/article/${item.id}/`); | ||
|
||
item.description = art(path.join(__dirname, 'templates/description.art'), { | ||
membership: data.article_for_membership, | ||
image: data.article_image, | ||
description: md.render(data.article_description), | ||
}); | ||
|
||
item.category = [...data.article_category.map((c) => c.category_name), ...data.article_tag.map((t) => t.tag_name)]; | ||
|
||
return item; | ||
}); |