feat(route): urbandictionary (#11969)

This commit is contained in:
Tony
2023-02-28 01:26:52 +08:00
committed by GitHub
parent 65eaa2a6d9
commit ee2b47020f
6 changed files with 60 additions and 0 deletions
+6
View File
@@ -287,6 +287,12 @@ Board and Build can be found in [here](http://api.ineal.me/tss/status)
</RouteEn>
## Urban Dictionary
### Random words
<RouteEn author="TonyRL" example="/urbandictionary/random" path="/urbandictionary/random" radar="1" rssbud="1"/>
## wikiHow
### Home
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/random': ['TonyRL'],
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'urbandictionary.com': {
_name: 'Urban Dictionary',
'.': [
{
title: 'Random words',
docs: 'https://docs.rsshub.app/en/other.html#urban-dictionary',
source: ['/random.php', '/'],
target: '/urbandictionary/random',
},
],
},
};
+24
View File
@@ -0,0 +1,24 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
module.exports = async (ctx) => {
const baseUrl = 'https://www.urbandictionary.com';
const { data } = await got('https://api.urbandictionary.com/v0/random');
const items = data.list.map((item) => ({
title: item.word,
description: art(path.join(__dirname, 'templates/definition.art'), { item }),
link: `${baseUrl}/define.php?term=${item.word}`,
guid: item.permalink,
pubDate: parseDate(item.written_on),
author: item.author,
}));
ctx.state.data = {
title: 'Urban Dictionary: Random words',
link: `${baseUrl}/random.php`,
item: items,
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/random', require('./random'));
};
@@ -0,0 +1,11 @@
{{ if item.definition }}
{{ item.definition }}<br>
{{ /if }}
{{ if item.example }}
<i>{{ item.example }}</i><br>
{{ /if }}
{{ if item.author }}
by <a href="https://www.urbandictionary.com/author.php?author={{ item.author }}">{{ item.author }}</a>
{{ /if }}