Files
RSSHub/lib/routes/aeon/utils.tsx
T
dependabot[bot]andTony 07834413f5 chore(deps-dev): bump eslint-plugin-unicorn from 64.0.0 to 65.0.0 (#22219)
* chore(deps-dev): bump eslint-plugin-unicorn from 64.0.0 to 65.0.0

Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 64.0.0 to 65.0.0.
- [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases)
- [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v64.0.0...v65.0.0)

---
updated-dependencies:
- dependency-name: eslint-plugin-unicorn
  dependency-version: 65.0.0
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix: no-array-from-fill

* fix: unicorn-js/no-duplicate-set-values

* fix: no-this-outside-of-class

* fix: no-unnecessary-nested-ternary

* fix: prefer-array-last-methods

* fix: prefer-queue-microtask

* fix: prefer-split-limit

* fix: no-array-from-fill

* fix: no-unused-array-method-return

* fix: prefer-single-call

* fix: prefer-includes-over-repeated-comparisons

* fix: consistent-compound-words

* fix: prefer-includes-over-repeated-comparisons

* chore: add eslint-plugin-unicorn v65 recommended preset

* fix: correct duration parsing logic in parseDuration function

* fix: update oxlint-disable

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tony <TonyRL@users.noreply.github.com>
2026-06-09 00:08:15 +08:00

149 lines
4.5 KiB
TypeScript

import { load } from 'cheerio';
import { raw } from 'hono/html';
import { renderToString } from 'hono/jsx/dom/server';
import cache from '@/utils/cache';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';
const ENDPOINT = 'https://api.aeonmedia.co/graphql';
const ESSAY = /* GraphQL */ `
query getAeonEssay($slug: String!) {
essay(slug: $slug) {
publishedAt
updatedAt
authors {
name
authorBio
}
audioUrl
image {
url
alt
caption
}
body
}
}
`;
const VIDEO = /* GraphQL */ `
query getAeonVideo($slug: String!, $site: SiteEnum!) {
video(slug: $slug, site: $site) {
publishedAt
updatedAt
authors {
name
authorBio
}
hoster
hosterId
credits
description
}
}
`;
const renderVideoDescription = (article) => {
let video = article.hosterId;
if (article.hoster === 'vimeo') {
video = `https://player.vimeo.com/video/${video}?dnt=1`;
} else if (article.hoster === 'youtube') {
video = `https://www.youtube-nocookie.com/embed/${video}`;
}
return renderToString(
<>
<iframe width="672" height="377" src={video} frameborder="0" allowfullscreen referrerpolicy="strict-origin-when-cross-origin"></iframe>
{article.credits ? raw(article.credits) : null}
{article.description ? raw(article.description) : null}
</>
);
};
const renderEssayDescription = ({ banner, authorsBio, content }) =>
renderToString(
<>
{banner?.url ? (
<figure>
<img src={banner.url} alt={banner.alt} />
{banner.caption ? <figcaption>{raw(banner.caption)}</figcaption> : null}
</figure>
) : null}
{authorsBio ? raw(authorsBio) : null}
{content ? raw(content) : null}
</>
);
const getJSON = (slug, site) => {
const query = site ? VIDEO : ESSAY;
const variables = site ? { slug, site } : { slug };
const operationName = site ? 'getAeonVideo' : 'getAeonEssay';
return ofetch(ENDPOINT, {
method: 'POST',
body: {
operationName,
query,
variables,
},
});
};
export const getData = async (list) => {
const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const res = await getJSON(item.slug, item.type === 'video' ? 'aeon' : null);
const data = res.data[item.type];
item.pubDate = parseDate(data.publishedAt);
if (item.type === 'video') {
item.description = renderVideoDescription(data);
} else {
if (data.audioUrl) {
delete item.image;
item.enclosure_url = data.audioUrl;
item.enclosure_type = 'audio/mpeg';
} else if (data.image?.url) {
const imageUrl = data.image.url;
const cleanImageUrl = imageUrl.split('?', 1)[0].toLowerCase();
item.enclosure_url = imageUrl;
if (cleanImageUrl.endsWith('.jpg') || cleanImageUrl.endsWith('.jpeg')) {
item.enclosure_type = 'image/jpeg';
}
item.image = imageUrl;
}
const capture = load(data.body, null, false);
const banner = data.image;
capture('p.pullquote').remove();
const authorsBio = renderToString(
<>
<hr />
{data.authors.map((author) => (
<p>
{author.name}
{raw(author.authorBio.replaceAll(/^<p>/g, ' '))}
</p>
))}
<hr />
<br />
</>
);
item.description = renderEssayDescription({ banner, authorsBio, content: capture.html() });
}
return item;
})
)
);
return items;
};