* add prettier

* lint-staged

* prettier

* upgrade husky
This commit is contained in:
nyagami
2024-03-23 22:00:29 +07:00
committed by GitHub
parent c22979b10f
commit 5f9a067ab9
113 changed files with 79244 additions and 50841 deletions
+24 -24
View File
@@ -1,43 +1,43 @@
import * as fs from "fs";
import * as cheerio from "cheerio";
import * as path from "path";
import list from "./sources.json";
import { HotNovelPubMetadata } from "./template";
import * as fs from 'fs';
import * as cheerio from 'cheerio';
import * as path from 'path';
import list from './sources.json';
import { HotNovelPubMetadata } from './template';
async function getFilters(sources: HotNovelPubMetadata) {
const filters: any = {
sort: {
type: "Picker",
label: "Order",
value: "hot",
type: 'Picker',
label: 'Order',
value: 'hot',
options: [],
},
category: {
type: "Picker",
label: "category",
value: "",
options: [{ label: "NONE", value: "" }],
type: 'Picker',
label: 'category',
value: '',
options: [{ label: 'NONE', value: '' }],
},
};
const body = await fetch(sources.sourceSite).then((res) => res.text());
const body = await fetch(sources.sourceSite).then(res => res.text());
const $: cheerio.CheerioAPI = cheerio.load(body);
$(".new-update").remove();
$('.new-update').remove();
$("section > div").each((i, el) => {
const id = $(el).find('a[class="see-all"]').attr("href");
$('section > div').each((i, el) => {
const id = $(el).find('a[class="see-all"]').attr('href');
if (id) {
filters.sort.options.push({
label: $(el).find('[class="section-title"]').text().trim(),
value: id.split("/").pop(),
value: id.split('/').pop(),
});
}
});
filters.category.label = $(".category-title").text().trim();
const apiSite = sources.sourceSite.replace("://", "://api.");
const jsonRaw = await fetch(apiSite + "/categories", {
filters.category.label = $('.category-title').text().trim();
const apiSite = sources.sourceSite.replace('://', '://api.');
const jsonRaw = await fetch(apiSite + '/categories', {
headers: {
lang: sources.options?.lang || "en",
lang: sources.options?.lang || 'en',
},
});
const json = (await jsonRaw.json()) as response;
@@ -45,7 +45,7 @@ async function getFilters(sources: HotNovelPubMetadata) {
if (json.data?.length) {
json.data
.sort((a, b) => a.name.localeCompare(b.name))
.forEach((category) =>
.forEach(category =>
filters.category.options.push({
label: category.name,
value: category.slug,
@@ -69,13 +69,13 @@ interface DataEntity {
async function start() {
const result = [];
for (const sources of list) {
console.log("updating the filters in", sources.sourceName);
console.log('updating the filters in', sources.sourceName);
const NewFilters = await getFilters(sources as any);
sources.filters = NewFilters;
result.push(sources);
}
fs.writeFileSync(
path.join(__dirname, "sources.json"),
path.join(__dirname, 'sources.json'),
JSON.stringify(result, null, 2),
);
}
+16 -15
View File
@@ -1,21 +1,21 @@
import { FilterTypes, Filters } from "../../../libs/filterInputs";
import { ScrpitGeneratorFunction } from "../generate";
import list from "./sources.json";
import { HotNovelPubMetadata } from "./template";
import { readFileSync } from "fs";
import path from "path";
import { FilterTypes, Filters } from '../../../libs/filterInputs';
import { ScrpitGeneratorFunction } from '../generate';
import list from './sources.json';
import { HotNovelPubMetadata } from './template';
import { readFileSync } from 'fs';
import path from 'path';
const lang: { [key: string]: string } = {
en: "english",
ru: "russian",
es: "spanish",
pt: "portuguese",
th: "turkish",
en: 'english',
ru: 'russian',
es: 'spanish',
pt: 'portuguese',
th: 'turkish',
};
export const generateAll: ScrpitGeneratorFunction = function (name) {
return list
.map<HotNovelPubMetadata>((p) => {
.map<HotNovelPubMetadata>(p => {
const filters: Filters = {};
for (const k in p.filters) {
const f = p.filters[k as keyof typeof p.filters];
@@ -36,8 +36,9 @@ export const generateAll: ScrpitGeneratorFunction = function (name) {
const generator = function generator(metadata: HotNovelPubMetadata) {
const HotNovelPubTemplate = readFileSync(
path.join(__dirname, "template.ts"), {
encoding: "utf-8",
path.join(__dirname, 'template.ts'),
{
encoding: 'utf-8',
},
);
@@ -51,7 +52,7 @@ export default plugin;
`.trim();
return {
lang: lang[metadata?.options?.lang || "en"] || "english",
lang: lang[metadata?.options?.lang || 'en'] || 'english',
filename: metadata.sourceName,
pluginScript,
};
+34 -32
View File
@@ -1,9 +1,9 @@
import { fetchFile, fetchApi } from "@libs/fetch";
import { Filters, FilterTypes } from "@libs/filterInputs";
import { Plugin } from "@typings/plugin";
import { NovelStatus } from "@libs/novelStatus";
import { load as parseHTML } from "cheerio";
import dayjs from "dayjs";
import { fetchFile, fetchApi } from '@libs/fetch';
import { Filters, FilterTypes } from '@libs/filterInputs';
import { Plugin } from '@typings/plugin';
import { NovelStatus } from '@libs/novelStatus';
import { load as parseHTML } from 'cheerio';
import dayjs from 'dayjs';
export interface HotNovelPubMetadata {
id: string;
@@ -32,23 +32,23 @@ class HotNovelPubPlugin implements Plugin.PluginBase {
this.name = metadata.sourceName;
this.icon = `multisrc/hotnovelpub/icons/${metadata.id}.png`;
this.site = metadata.sourceSite;
this.apiSite = metadata.sourceSite.replace("://", "://api.");
this.version = "1.0.0";
this.apiSite = metadata.sourceSite.replace('://', '://api.');
this.version = '1.0.0';
this.filters = metadata.filters;
this.lang = metadata.options?.lang || "en";
this.lang = metadata.options?.lang || 'en';
}
async popularNovels(
pageNo: number,
{ filters, showLatestNovels }: Plugin.PopularNovelsOptions,
): Promise<Plugin.NovelItem[]> {
let url = this.apiSite + "/books/";
url += showLatestNovels ? "new" : filters?.sort?.value || "hot";
let url = this.apiSite + '/books/';
url += showLatestNovels ? 'new' : filters?.sort?.value || 'hot';
if (filters?.category?.value) {
url = this.apiSite + "/category/" + filters.category.value;
url = this.apiSite + '/category/' + filters.category.value;
}
url += "/?page=" + (pageNo - 1) + "&limit=20";
url += '/?page=' + (pageNo - 1) + '&limit=20';
const result = await fetchApi(url, {
headers: {
@@ -59,11 +59,11 @@ class HotNovelPubPlugin implements Plugin.PluginBase {
const novels: Plugin.NovelItem[] = [];
if (json.status && json.data.books.data?.length) {
json.data.books.data.forEach((novel) =>
json.data.books.data.forEach(novel =>
novels.push({
name: novel.name,
cover: this.site + novel.image,
path: "/" + novel.slug,
path: '/' + novel.slug,
}),
);
}
@@ -71,7 +71,7 @@ class HotNovelPubPlugin implements Plugin.PluginBase {
}
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
const result = await fetchApi(this.apiSite + "/book" + novelPath, {
const result = await fetchApi(this.apiSite + '/book' + novelPath, {
headers: {
lang: this.lang,
},
@@ -85,13 +85,13 @@ class HotNovelPubPlugin implements Plugin.PluginBase {
summary: json.data.book.authorize.description,
author: json.data.book.authorize.name,
status:
json.data.book.status === "updating"
json.data.book.status === 'updating'
? NovelStatus.Ongoing
: NovelStatus.Completed,
};
if (json.data.tags.tags_name?.length) {
novel.genres = json.data.tags.tags_name.join(",");
novel.genres = json.data.tags.tags_name.join(',');
}
if (json.data.chapters?.length) {
@@ -99,7 +99,7 @@ class HotNovelPubPlugin implements Plugin.PluginBase {
json.data.chapters.forEach((chapter, chapterIndex) =>
chapters.push({
name: chapter.title,
path: "/" + chapter.slug,
path: '/' + chapter.slug,
releaseTime: undefined,
chapterNumber: (chapter.index || chapterIndex) + 1,
}),
@@ -111,50 +111,52 @@ class HotNovelPubPlugin implements Plugin.PluginBase {
}
async parseChapter(chapterPath: string): Promise<string> {
const body = await fetchApi(this.site + chapterPath).then((res) => res.text());
const body = await fetchApi(this.site + chapterPath).then(res =>
res.text(),
);
const loadedCheerio = parseHTML(body);
let chapterText = loadedCheerio("#content-item").html() || "";
let chapterText = loadedCheerio('#content-item').html() || '';
if (chapterText) {
const result = await fetchApi(
this.site + "/server/getContent?slug=" + chapterPath,
this.site + '/server/getContent?slug=' + chapterPath,
);
const json = (await result.json()) as ChapterType;
if (json.data) {
chapterText += json.data
.map((item) => "<p>" + item + "</p>")
.join("")
.replace(/\n/g, "</p><p>")
.replace(/\s/g, " ");
.map(item => '<p>' + item + '</p>')
.join('')
.replace(/\n/g, '</p><p>')
.replace(/\s/g, ' ');
}
}
return chapterText.replace(/\.copy right hot novel pub/g, "");
return chapterText.replace(/\.copy right hot novel pub/g, '');
}
async searchNovels(
searchTerm: string,
pageNo: number,
): Promise<Plugin.NovelItem[]> {
const result = await fetchApi(this.apiSite + "/search", {
const result = await fetchApi(this.apiSite + '/search', {
headers: {
"Content-Type": "application/json;charset=utf-8",
'Content-Type': 'application/json;charset=utf-8',
Referer: this.site,
Origin: this.site,
lang: this.lang,
},
method: "POST",
method: 'POST',
body: JSON.stringify({ key_search: searchTerm }),
});
const json = (await result.json()) as responseSearch;
const novels: Plugin.NovelItem[] = [];
if (json.status && json.data.books?.length) {
json.data.books.forEach((novel) =>
json.data.books.forEach(novel =>
novels.push({
name: novel.name,
cover: undefined,
path: "/" + novel.slug,
path: '/' + novel.slug,
}),
);
}