refactor: replace art template with jsx (#20777)
* refactor: replace art template with jsx * fix: tsx files * fix: renderToString import * fix: hono html raw import * feat: remove art
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import { load } from 'cheerio';
|
||||
import { raw } from 'hono/html';
|
||||
import { renderToString } from 'hono/jsx/dom/server';
|
||||
|
||||
import type { Route } from '@/types';
|
||||
import got from '@/utils/got';
|
||||
import md5 from '@/utils/md5';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import { art } from '@/utils/render';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/pulse/:user/:repo/:period?',
|
||||
@@ -103,11 +102,31 @@ async function handler(ctx) {
|
||||
{
|
||||
guid: md5(`${user}${repo}${period}${periodFrom}${periodTo}`),
|
||||
title: `${periodFrom} - ${periodTo}`,
|
||||
description: art(path.join(__dirname, 'templates/pulse-description.art'), {
|
||||
overviewItems,
|
||||
commitActivity,
|
||||
githubActivity,
|
||||
}),
|
||||
description: renderToString(
|
||||
<>
|
||||
<h2>Overview</h2>
|
||||
<ul>
|
||||
{overviewItems.map((item) => (
|
||||
<li>{item}</li>
|
||||
))}
|
||||
</ul>
|
||||
{commitActivity ? raw(commitActivity) : null}
|
||||
{(githubActivity ?? []).map((activity) => (
|
||||
<>
|
||||
<h2>{activity.heading}</h2>
|
||||
{activity.paragraph ? <p>{activity.paragraph}</p> : null}
|
||||
<ul>
|
||||
{activity.items.map((item) => (
|
||||
<li>
|
||||
<a href={item.link.url}>{item.link.text}</a>
|
||||
<p>{item.details}</p>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</>
|
||||
))}
|
||||
</>
|
||||
),
|
||||
pubDate: parseDate(periodTo),
|
||||
},
|
||||
],
|
||||
@@ -1 +0,0 @@
|
||||
{{@ desc }}
|
||||
@@ -1,24 +0,0 @@
|
||||
<h2>Overview</h2>
|
||||
|
||||
<ul>
|
||||
{{each overviewItems item}}
|
||||
<li>{{item}}</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
|
||||
{{@ commitActivity}}
|
||||
|
||||
{{each githubActivity activity}}
|
||||
<h2>{{activity.heading}}</h2>
|
||||
{{if activity.paragraph}}
|
||||
<p>{{activity.paragraph}}</p>
|
||||
{{/if}}
|
||||
<ul>
|
||||
{{each activity.items item}}
|
||||
<li>
|
||||
<a href="{{item.link.url}}">{{item.link.text}}</a>
|
||||
<p>{{item.details}}</p>
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
{{/each}}
|
||||
@@ -1,5 +0,0 @@
|
||||
<img src="{{@ cover }}">
|
||||
<br>{{@ desc }}
|
||||
<br><br>Language: {{@ lang }}
|
||||
<br>Stars: {{@ stars }}
|
||||
<br>Forks: {{@ forks }}
|
||||
@@ -1,13 +1,12 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import { load } from 'cheerio';
|
||||
import { raw } from 'hono/html';
|
||||
import { renderToString } from 'hono/jsx/dom/server';
|
||||
|
||||
import { config } from '@/config';
|
||||
import ConfigNotFoundError from '@/errors/types/config-not-found';
|
||||
import type { Route } from '@/types';
|
||||
import { ViewType } from '@/types';
|
||||
import got from '@/utils/got';
|
||||
import { art } from '@/utils/render';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/trending/:since/:language/:spoken_language?',
|
||||
@@ -137,13 +136,20 @@ async function handler(ctx) {
|
||||
item: repos.map((r) => ({
|
||||
title: r.nameWithOwner,
|
||||
author: r.owner,
|
||||
description: art(path.join(__dirname, 'templates/trending-description.art'), {
|
||||
cover: r.openGraphImageUrl,
|
||||
desc: r.description,
|
||||
forks: r.forkCount,
|
||||
lang: r.primaryLanguage?.name || 'Unknown',
|
||||
stars: r.stargazerCount,
|
||||
}),
|
||||
description: renderToString(
|
||||
<>
|
||||
<img src={r.openGraphImageUrl} />
|
||||
<br />
|
||||
{r.description ? raw(r.description) : null}
|
||||
<br />
|
||||
<br />
|
||||
Language: {raw(r.primaryLanguage?.name || 'Unknown')}
|
||||
<br />
|
||||
Stars: {raw(String(r.stargazerCount))}
|
||||
<br />
|
||||
Forks: {raw(String(r.forkCount))}
|
||||
</>
|
||||
),
|
||||
link: `https://github.com/${r.nameWithOwner}`,
|
||||
})),
|
||||
};
|
||||
Reference in New Issue
Block a user