diff --git a/docs/en/other.md b/docs/en/other.md index 19761b54c..d88422ede 100644 --- a/docs/en/other.md +++ b/docs/en/other.md @@ -287,6 +287,12 @@ Board and Build can be found in [here](http://api.ineal.me/tss/status) +## Urban Dictionary + +### Random words + + + ## wikiHow ### Home diff --git a/lib/v2/urbandictionary/maintainer.js b/lib/v2/urbandictionary/maintainer.js new file mode 100644 index 000000000..327676bb2 --- /dev/null +++ b/lib/v2/urbandictionary/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/random': ['TonyRL'], +}; diff --git a/lib/v2/urbandictionary/radar.js b/lib/v2/urbandictionary/radar.js new file mode 100644 index 000000000..eee16241e --- /dev/null +++ b/lib/v2/urbandictionary/radar.js @@ -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', + }, + ], + }, +}; diff --git a/lib/v2/urbandictionary/random.js b/lib/v2/urbandictionary/random.js new file mode 100644 index 000000000..84a58964d --- /dev/null +++ b/lib/v2/urbandictionary/random.js @@ -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, + }; +}; diff --git a/lib/v2/urbandictionary/router.js b/lib/v2/urbandictionary/router.js new file mode 100644 index 000000000..9d7822ee3 --- /dev/null +++ b/lib/v2/urbandictionary/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/random', require('./random')); +}; diff --git a/lib/v2/urbandictionary/templates/definition.art b/lib/v2/urbandictionary/templates/definition.art new file mode 100644 index 000000000..9b3285f08 --- /dev/null +++ b/lib/v2/urbandictionary/templates/definition.art @@ -0,0 +1,11 @@ +{{ if item.definition }} + {{ item.definition }}
+{{ /if }} + +{{ if item.example }} + {{ item.example }}
+{{ /if }} + +{{ if item.author }} + by {{ item.author }} +{{ /if }}