rsshub
Version:
Make RSS Great Again!
61 lines (60 loc) • 2.38 kB
JavaScript
import { t as rofetch } from "./ofetch-C3ts-Hud.mjs";
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs";
import { t as cache_default } from "./cache-BkqOokyU.mjs";
import { t as timezone } from "./timezone-BBvDwS_3.mjs";
import { load } from "cheerio";
//#region lib/routes/mhlw/monthly-labour-survey.ts
const route = {
path: "/monthly-labour-survey",
categories: ["government"],
example: "/mhlw/monthly-labour-survey",
radar: [{ source: ["www.mhlw.go.jp/toukei/list/30-1a.html"] }],
name: "毎月勤労統計調査 全国調査(月別結果)",
maintainers: ["TonyRL"],
handler,
url: "www.mhlw.go.jp/toukei/list/30-1a.html"
};
const parseJapaneseDate = (text) => {
return parseDate(text.replaceAll(/([^)]+)/g, "").replaceAll(/[0-9]/g, (c) => String.fromCodePoint(c.codePointAt(0) - 65248)).replace(/^令和(\d+)年/, (_, year) => `${Number(year) + 2018}年`), "YYYY年M月D日");
};
async function fetchPage(url) {
const raw = await rofetch(url, { responseType: "arrayBuffer" });
return new TextDecoder("shift-jis").decode(raw);
}
async function handler(ctx) {
const limit = Number(ctx.req.query("limit") || "24");
const baseUrl = "https://www.mhlw.go.jp";
const link = `${baseUrl}/toukei/list/30-1a.html`;
const $ = load(await fetchPage(link));
const list = $("table.xgengo:first tr").toArray().flatMap((row) => {
const $row = $(row);
const year = $row.find("h3").text();
return $row.find("ul.ico-link li a").toArray().map((a) => {
const $a = $(a);
return {
title: `${year}${$a.text()}`,
link: new URL($a.attr("href"), baseUrl).href
};
}).toReversed();
}).slice(0, limit);
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const $ = load(await fetchPage(item.link));
const dateText = $(".prt-topContents .al-right").text();
const content = $("#contentsInner");
content.find(".prt-topContents, .prt-linkNavi, .prt-plugin").remove();
item.title = $("h1#pageTitle").text().trim() || item.title;
item.pubDate = timezone(parseJapaneseDate(dateText), 9);
item.description = content.html()?.trim();
return item;
})));
return {
title: $("head title").text(),
description: $("meta[name=\"description\"]").attr("content"),
link,
image: `${baseUrl}/favicon.ico`,
language: $("html").attr("lang"),
item: items
};
}
//#endregion
export { route };