Skip to content

Commit

Permalink
fix(source): NovelOnline: Add Popular Novels (LNReader#832)
Browse files Browse the repository at this point in the history
Closes LNReader/lnreader-plugins#638

---------

Co-authored-by: Rajarshee Chatterjee <rajarshee.adm@gmail.com>
  • Loading branch information
NewbieAnimeManga and rajarsheechatterjee authored Nov 6, 2023
1 parent f069a67 commit ee9391b
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions src/sources/en/NovelOnline.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { fetchHtml } from '@utils/fetch/fetch';
import * as cheerio from 'cheerio';
import {
SourceChapter,
SourceChapterItem,
SourceNovel,
SourceNovelItem,
} from '../types';
import { SourceChapterItem, SourceNovel, SourceNovelItem } from '../types';

const sourceId = 163;
const sourceName = 'novelsOnline';

// const baseUrl = 'https://novelsonline.net';
const baseUrl = 'https://novelsonline.net';

const searchNovels = async (searchTerm: string) => {
const result = await fetchHtml({
Expand Down Expand Up @@ -101,26 +96,31 @@ const parseNovelAndChapters = async (novelUrl: string) => {
return novel;
};

const popularNovels = async () => {
return { novels: [] as SourceNovelItem[] }; /** TO DO */
};

const parseChapter = async (novelUrl: string, chapterUrl: string) => {
const result = await fetchHtml({ url: chapterUrl });
let loadedCheerio = cheerio.load(result);
const popularNovels = async (page: number) => {
const url = `${baseUrl}/top-novel/${page}`;
const result = await fetchHtml({ sourceId, url });
let $ = cheerio.load(result);

const chapterName = loadedCheerio('h1').text();
const chapterText = loadedCheerio('#contentall').html() || '';
const headers = $('div.top-novel-block');
return headers
.map((i, h) => {
const novelName = $(h).find('h2').text();
const novelUrl = $(h).find('a').attr('href');
const novelCover = $(h).find('img').attr('src');

const chapter: SourceChapter = {
sourceId,
novelUrl,
chapterUrl,
chapterName,
chapterText,
};
if (!novelUrl) {
return null;
}

return chapter;
return {
sourceId,
novelName,
novelCover,
novelUrl,
} as SourceNovelItem;
})
.get()
.filter(sr => sr !== null);
};

const NovelsOnlineScraper = {
Expand Down

0 comments on commit ee9391b

Please sign in to comment.