Skip to content

Commit

Permalink
feat(route): Add ekantipur.com (Nepal) (#14207)
Browse files Browse the repository at this point in the history
* feat(route): Add ekantipur remove unused deps

* feat(route): Add ekantipur radar

* removed undefined field

* updated maintainer.js to use optional field character - ?

* updated radar.js with full name

---------
  • Loading branch information
maniche04 authored Jan 10, 2024
1 parent 12b409f commit 327d0d0
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 0 deletions.
64 changes: 64 additions & 0 deletions lib/v2/ekantipur/issue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Require necessary modules
const got = require('@/utils/got'); // a customised got
const cheerio = require('cheerio'); // an HTML parser with a jQuery-like API

module.exports = async (ctx) => {
// Your logic here
// Defining base URL
const baseUrl = 'https://ekantipur.com';

// Retrive the channel parameter
const { channel = 'news' } = ctx.params;

// Fetches content of the requested channel
const { data: response } = await got(`${baseUrl}/${channel}`);
const $ = cheerio.load(response);

// Retrive articles
const list = $('article.normal')
// We use the `toArray()` method to retrieve all the DOM elements selected as an array.
.toArray()
// We use the `map()` method to traverse the array and parse the data we need from each element.
.map((item) => {
item = $(item);
const a = item.find('a').first();
return {
title: a.text(),
// We need an absolute URL for `link`, but `a.attr('href')` returns a relative URL.
link: `${baseUrl}${a.attr('href')}`,
author: item.find('div.author').text(),
category: channel,
};
});

const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);

// Remove sponsor elements
$('a.static-sponsor').remove();
$('div.ekans-wrapper').remove();

// Fetch title from the article page
item.title = $('h1.eng-text-heading').text();
// Fetch article content from the article page
item.description = $('div.current-news-block').first().html();

// Every property of a list item defined above is reused here
// and we add a new property 'description'
return item;
})
)
);

ctx.state.data = {
// channel title
title: `Ekantipur - ${channel}`,
// channel link
link: `${baseUrl}/${channel}`,
// each feed item
item: items,
};
};
3 changes: 3 additions & 0 deletions lib/v2/ekantipur/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:channel?': ['maniche04'],
};
13 changes: 13 additions & 0 deletions lib/v2/ekantipur/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'ekantipur.com': {
_name: 'Ekantipur',
'.': [
{
title: 'Full Article RSS',
docs: 'https://docs.rsshub.app/routes/traditional-media#ekantipur-%E0%A4%95%E0%A4%BE%E0%A4%A8%E0%A5%8D%E0%A4%A4%E0%A4%BF%E0%A4%AA%E0%A5%81%E0%A4%B0-nepal',
source: ['/:channel'],
target: '/ekantipur/:channel',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/ekantipur/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:channel?', require('./issue'));
};
12 changes: 12 additions & 0 deletions website/docs/routes/traditional-media.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,18 @@
:::
</Route>

## Ekantipur / कान्तिपुर (Nepal)

### Full Article RSS {#ekantipur-rss}

<Route author="maniche04" example="/ekantipur/news" path="/ekantipur/:channel?" paramsDesc={['Find it in the ekantipur.com menu or pick from the list below:']} radar="1">
Channels:

| समाचार | अर्थ / वाणिज्य | विचार | खेलकुद | उपत्यका | मनोरञ्जन | फोटोफिचर | फिचर | विश्व | ब्लग |
| --------- | --------- | ----- | ------------- | ------ | ----- | --------- | --------- | -------- | ----- |
| news | business | opinion | sports | national | entertainment | photo_feature | feature | world | blog |
</Route>

## Financial Times {#financial-times}

### FT 中文网 {#financial-times-ft-zhong-wen-wang}
Expand Down

0 comments on commit 327d0d0

Please sign in to comment.