Files
RSSHub/lib/routes/devolverdigital/blog.ts
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

95 lines
3.0 KiB
TypeScript

import { load } from 'cheerio';
import type { DataItem, Route } from '@/types';
import ofetch from '@/utils/ofetch';
export const route: Route = {
path: '/blog',
categories: ['game'],
example: '/devolverdigital/blog',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['devolverdigital.com/blog'],
},
],
name: 'Official Blogs',
maintainers: ['XXY233'],
handler,
url: 'devolverdigital.com/blog',
};
async function handler() {
const items = await fetchPage();
return {
title: 'DevolverDigital Blog',
language: 'en-us',
link: 'https://www.devolverdigital.com/blog',
item: items,
};
}
async function fetchPage() {
const baseUrl = 'https://www.devolverdigital.com/blog';
const response = await ofetch(baseUrl);
const $ = load(response, { scriptingEnabled: false });
// Extract all posts of this page
const $titleDivs = $('div.w-full.flex.justify-center.py-4.bg-red-400.undefined');
const $contentDivs = $('div.bg-gray-800.flex.justify-center.font-sm.py-4');
const items: DataItem[] = $titleDivs.toArray().map((titleDiv, index) => {
const content = $contentDivs[index];
const postAuthor = parsePostAuthor($, titleDiv);
const postDate = parsePostDate($, titleDiv);
const postTitle = $(titleDiv).find('h1').text();
const postLink = $(content).find('div.ml-auto.flex.items-center a').attr('href');
// Modify the src attribute of the image
parsePostImages($, content);
const postContent = $.html($(content).find('div.cms-content'));
return {
title: postTitle,
link: postLink,
author: postAuthor,
pubDate: postDate,
description: postContent,
};
});
return items;
}
function parsePostAuthor($, titleDiv) {
const $postAuthorElement = $(titleDiv).find('div.font-xs.leading-none.mb-1');
return $postAuthorElement.text().replace('By ', '') || 'Devolver Digital';
}
function parsePostDate($, titleDiv) {
const dateStr = $(titleDiv).find('div.font-2xs.leading-none.mb-1').text();
const cleanedDateStr = dateStr.replace(/(\d+)(st|nd|rd|th)/, '$1');
return new Date(cleanedDateStr);
}
function parsePostImages($, content) {
$(content)
.find('img')
.each((index, img) => {
const $img = $(img);
const src = $img.attr('src') || '';
if (src.startsWith('/_next/image')) {
const srcSet = $img.attr('srcset') || '';
const actualSrc = srcSet.split(',').pop()?.split(' ', 1)[0] || src;
$img.attr('src', actualSrc);
}
$img.removeAttr('loading').removeAttr('decoding').removeAttr('data-nimg').removeAttr('style').removeAttr('sizes').removeAttr('srcset').removeAttr('referrerpolicy');
});
}