diff --git a/lib/v2/thoughtco/index.js b/lib/v2/thoughtco/index.js new file mode 100644 index 00000000000000..ba83a8c7a5d669 --- /dev/null +++ b/lib/v2/thoughtco/index.js @@ -0,0 +1,95 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const { category = '' } = ctx.params; + const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 50; + + const rootUrl = 'https://www.thoughtco.com'; + const currentUrl = new URL(category, rootUrl).href; + + const { data: response } = await got(currentUrl); + + const $ = cheerio.load(response); + + let items = $('a[data-doc-id]') + .slice(0, limit) + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.find('span.block-title').text(), + link: new URL(item.prop('href'), rootUrl).href, + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: detailResponse } = await got(item.link); + + const content = cheerio.load(detailResponse); + + content('div.adslot').remove(); + content('div.sources-and-citation, .mntl-figure-caption svg').remove(); + content('div.figure-media').each((_, e) => { + e = $(e); + + const image = e.find('img'); + + e.replaceWith( + art(path.join(__dirname, 'templates/description.art'), { + image: { + src: image.prop('data-src'), + width: image.prop('width'), + height: image.prop('height'), + }, + }) + ); + }); + + item.title = content('meta[property="og:title"]').prop('content'); + item.description = art(path.join(__dirname, 'templates/description.art'), { + image: { + src: content('meta[property="og:image"]').prop('content'), + }, + description: content('div.article-content').html(), + }); + item.author = content('meta[name="sailthru.author"]').prop('content'); + item.category = Array.from( + new Set( + content('meta[name="parsely-tags"]') + .prop('content') + .split(/,/) + .map((c) => c.trim()) + ) + ); + item.pubDate = parseDate(detailResponse.match(/"datePublished": "(.*?)"/)[1]); + item.updated = parseDate(detailResponse.match(/"dateModified": "(.*?)"/)[1]); + + return item; + }) + ) + ); + + const author = $('meta[property="og:site_name"]').prop('content'); + const title = $('meta[property="og:title"]').prop('content'); + const icon = new URL($('link[rel="apple-touch-icon-precomposed"]').prop('href'), rootUrl).href; + + ctx.state.data = { + item: items, + title: `${author}${title.startsWith(author) ? '' : ` - ${title}`}`, + link: currentUrl, + description: $('meta[property="og:description"]').prop('content'), + language: $('html').prop('lang'), + image: $('meta[property="og:image"]').prop('content'), + icon, + logo: icon, + subtitle: $('meta[property="og:title"]').prop('content'), + author, + }; +}; diff --git a/lib/v2/thoughtco/maintainer.js b/lib/v2/thoughtco/maintainer.js new file mode 100644 index 00000000000000..81eb78d7328b63 --- /dev/null +++ b/lib/v2/thoughtco/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:category?': ['nczitzk'], +}; diff --git a/lib/v2/thoughtco/radar.js b/lib/v2/thoughtco/radar.js new file mode 100644 index 00000000000000..ed303dc65ababb --- /dev/null +++ b/lib/v2/thoughtco/radar.js @@ -0,0 +1,155 @@ +module.exports = { + 'thoughtco.com': { + _name: 'ThoughtCo', + '.': [ + { + title: 'Category', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category', + source: ['/:category'], + target: (params) => { + const category = params.category; + + return `/thoughtco${category ? `/${category}` : ''}`; + }, + }, + { + title: 'Science, Tech, Math - Science', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-science-tech-math', + source: ['/science-4132464'], + target: '/thoughtco/science-4132464', + }, + { + title: 'Science, Tech, Math - Math', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-science-tech-math', + source: ['/math-4133545'], + target: '/thoughtco/math-4133545', + }, + { + title: 'Science, Tech, Math - Social Sciences', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-science-tech-math', + source: ['/social-sciences-4133522'], + target: '/thoughtco/social-sciences-4133522', + }, + { + title: 'Science, Tech, Math - Computer Science', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-science-tech-math', + source: ['/computer-science-4133486'], + target: '/thoughtco/computer-science-4133486', + }, + { + title: 'Science, Tech, Math - Animals & Nature', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-science-tech-math', + source: ['/animals-and-nature-4133421'], + target: '/thoughtco/animals-and-nature-4133421', + }, + { + title: 'Humanities - History & Culture', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-humanities', + source: ['/history-and-culture-4133356'], + target: '/thoughtco/history-and-culture-4133356', + }, + { + title: 'Humanities - Visual Arts', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-humanities', + source: ['/visual-arts-4132957'], + target: '/thoughtco/visual-arts-4132957', + }, + { + title: 'Humanities - Literature', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-humanities', + source: ['/literature-4133251'], + target: '/thoughtco/literature-4133251', + }, + { + title: 'Humanities - English', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-humanities', + source: ['/english-4688281'], + target: '/thoughtco/english-4688281', + }, + { + title: 'Humanities - Geography', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-humanities', + source: ['/geography-4133035'], + target: '/thoughtco/geography-4133035', + }, + { + title: 'Humanities - Philosophy', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-humanities', + source: ['/philosophy-4133025'], + target: '/thoughtco/philosophy-4133025', + }, + { + title: 'Humanities - Issues', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-humanities', + source: ['/issues-4133022'], + target: '/thoughtco/issues-4133022', + }, + { + title: 'Languages - English as a Second Language', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-languages', + source: ['/esl-4133095'], + target: '/thoughtco/esl-4133095', + }, + { + title: 'Languages - Spanish', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-languages', + source: ['/spanish-4133085'], + target: '/thoughtco/spanish-4133085', + }, + { + title: 'Languages - French', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-languages', + source: ['/french-4133079'], + target: '/thoughtco/french-4133079', + }, + { + title: 'Languages - German', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-languages', + source: ['/german-4133073'], + target: '/thoughtco/german-4133073', + }, + { + title: 'Languages - Italian', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-languages', + source: ['/italian-4133069'], + target: '/thoughtco/italian-4133069', + }, + { + title: 'Languages - Japanese', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-languages', + source: ['/japanese-4133062'], + target: '/thoughtco/japanese-4133062', + }, + { + title: 'Languages - Mandarin', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-languages', + source: ['/mandarin-4133057'], + target: '/thoughtco/mandarin-4133057', + }, + { + title: 'Languages - Russian', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-languages', + source: ['/russian-4175265'], + target: '/thoughtco/russian-4175265', + }, + { + title: 'Resources - For Students & Parents', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-resources', + source: ['/for-students-parents-4132588'], + target: '/thoughtco/for-students-parents-4132588', + }, + { + title: 'Resources - For Educators', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-resources', + source: ['/for-educators-4132509'], + target: '/thoughtco/for-educators-4132509', + }, + { + title: 'Resources - For Adult Learners', + docs: 'https://docs.rsshub.app/routes/new-media#thoughtco-category-resources', + source: ['/for-adult-learners-4132469'], + target: '/thoughtco/for-adult-learners-4132469', + }, + ], + }, +}; diff --git a/lib/v2/thoughtco/router.js b/lib/v2/thoughtco/router.js new file mode 100644 index 00000000000000..19b84c05d31da0 --- /dev/null +++ b/lib/v2/thoughtco/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:category?', require('./')); +}; diff --git a/lib/v2/thoughtco/templates/description.art b/lib/v2/thoughtco/templates/description.art new file mode 100644 index 00000000000000..1eac078aef91f9 --- /dev/null +++ b/lib/v2/thoughtco/templates/description.art @@ -0,0 +1,16 @@ +{{ if image }} +
+ +
+{{ /if }} + +{{ if description }} + {{@ description }} +{{ /if }} \ No newline at end of file diff --git a/website/docs/routes/new-media.md b/website/docs/routes/new-media.md index 7e1bbcdf240aa4..73c185454919dc 100644 --- a/website/docs/routes/new-media.md +++ b/website/docs/routes/new-media.md @@ -2097,6 +2097,311 @@ Provides a better reading experience (full text articles) over the official one. +## ThoughtCo {#thoughtco} + +### Category {#thoughtco-category} + + + +#### Science, Tech, Math {#thoughtco-category-science-tech-math} + +| category | id | +| ---------------- | -------------------------- | +| Science | science-4132464 | +| Math | math-4133545 | +| Social Sciences | social-sciences-4133522 | +| Computer Science | computer-science-4133486 | +| Animals & Nature | animals-and-nature-4133421 | + +#### Humanities {#thoughtco-category-humanities} + +| category | id | +| ----------------- | --------------------------- | +| History & Culture | history-and-culture-4133356 | +| Visual Arts | visual-arts-4132957 | +| Literature | literature-4133251 | +| English | english-4688281 | +| Geography | geography-4133035 | +| Philosophy | philosophy-4133025 | +| Issues | issues-4133022 | + +#### Languages {#thoughtco-category-languages} + +| category | id | +| ---------------------------- | ---------------- | +| English as a Second Language | esl-4133095 | +| Spanish | spanish-4133085 | +| French | french-4133079 | +| German | german-4133073 | +| Italian | italian-4133069 | +| Japanese | japanese-4133062 | +| Mandarin | mandarin-4133057 | +| Russian | russian-4175265 | + +#### Resources {#thoughtco-category-resources} + +| category | id | +| ---------------------- | ---------------------------- | +| For Students & Parents | for-students-parents-4132588 | +| For Educators | for-educators-4132509 | +| For Adult Learners | for-adult-learners-4132469 | + +
+ More categories + +#### Science {#thoughtco-category-science} + + | category | id | + | ----------------- | --------------------------- | + | Chemistry | chemistry-4133594 | + | Biology | biology-4133580 | + | Physics | physics-4133571 | + | Geology | geology-4133564 | + | Astronomy | astronomy-4133558 | + | Weather & Climate | weather-and-climate-4133550 | + +#### Math {#thoughtco-category-math} + + | category | id | + | --------------------- | ------------------------------- | + | Math Tutorials | math-tutorials-4133543 | + | Geometry | geometry-4133540 | + | Arithmetic | arithmetic-4133542 | + | Pre Algebra & Algebra | pre-algebra-and-algebra-4133541 | + | Statistics | statistics-4133539 | + | Exponential Decay | exponential-decay-4133528 | + | Worksheets By Grade | worksheets-by-grade-4133526 | + | Resources | math-resources-4133523 | + +#### Social Sciences {#thoughtco-category-social-sciences} + + | category | id | + | ----------- | ------------------- | + | Psychology | psychology-4160512 | + | Sociology | sociology-4133515 | + | Archaeology | archaeology-4133504 | + | Economics | economics-4133521 | + | Ergonomics | ergonomics-4133492 | + +#### Computer Science {#thoughtco-category-computer-science} + + | category | id | + | ---------------------- | -------------------------------- | + | PHP Programming | php-4133485 | + | Perl | perl-4133481 | + | Python | python-4133477 | + | Java Programming | java-programming-4133478 | + | Javascript Programming | javascript-programming-4133476 | + | Delphi Programming | delphi-programming-4133475 | + | C & C++ Programming | c-and-c-plus-programming-4133470 | + | Ruby Programming | ruby-programming-4133469 | + | Visual Basic | visual-basic-4133468 | + +#### Animals and Nature {#thoughtco-category-animals-and-nature} + + | category | id | + | ---------------- | ------------------------ | + | Amphibians | amphibians-4133418 | + | Birds | birds-4133416 | + | Habitat Profiles | habitat-profiles-4133412 | + | Mammals | mammals-4133411 | + | Reptiles | reptiles-4133408 | + | Insects | insects-4133406 | + | Marine Life | marine-life-4133393 | + | Forestry | forestry-4133386 | + | Dinosaurs | dinosaurs-4133376 | + | Evolution | evolution-4133366 | + +#### History and Culture {#thoughtco-category-history-and-culture} + + | category | id | + | ------------------------------ | ---------------------------------------- | + | American History | american-history-4133354 | + | African American History | african-american-history-4133344 | + | African History | african-history-4133338 | + | Ancient History and Culture | ancient-history-4133336 | + | Asian History | asian-history-4133325 | + | European History | european-history-4133316 | + | Genealogy | genealogy-4133308 | + | Inventions | inventions-4133303 | + | Latin American History | latin-american-history-4133296 | + | Medieval & Renaissance History | medieval-and-renaissance-history-4133289 | + | Military History | military-history-4133285 | + | The 20th Century | 20th-century-4133273 | + | Women's History | womens-history-4133260 | + +#### Visual Arts {#thoughtco-category-visual-arts} + + | category | id | + | ------------- | -------------------- | + | Art & Artists | art-4132956 | + | Architecture | architecture-4132953 | + +#### Literature {#thoughtco-category-literature} + + | category | id | + | ------------------ | -------------------------- | + | Best Sellers | best-sellers-4133250 | + | Classic Literature | classic-literature-4133245 | + | Plays & Drama | plays-and-drama-4133239 | + | Poetry | poetry-4133232 | + | Quotations | quotations-4133229 | + | Shakespeare | shakespeare-4133223 | + | Short Stories | short-stories-4133217 | + | Children's Books | childrens-books-4133216 | + +#### English {#thoughtco-category-english} + + | category | id | + | --------------- | ----------------------- | + | English Grammar | english-grammar-4133049 | + | Writing | writing-4133048 | + +#### Geography {#thoughtco-category-geography} + + | category | id | + | ------------------------ | ---------------------------------- | + | Basics | geography-basics-4133034 | + | Physical Geography | physical-geography-4133032 | + | Political Geography | political-geography-4133033 | + | Population | population-4133031 | + | Country Information | country-information-4133030 | + | Key Figures & Milestones | key-figures-and-milestones-4133029 | + | Maps | maps-4133027 | + | Urban Geography | urban-geography-4133026 | + +#### Philosophy {#thoughtco-category-philosophy} + + | category | id | + | ------------------------------ | ---------------------------------------- | + | Philosophical Theories & Ideas | philosophical-theories-and-ideas-4133024 | + | Major Philosophers | major-philosophers-4133023 | + +#### Issues {#thoughtco-category-issues} + + | category | id | + | --------------------------------- | -------------------------------- | + | The U. S. Government | us-government-4133021 | + | U.S. Foreign Policy | us-foreign-policy-4133010 | + | U.S. Liberal Politics | us-liberal-politics-4133009 | + | U.S. Conservative Politics | us-conservative-politics-4133006 | + | Women's Issues | womens-issues-4133002 | + | Civil Liberties | civil-liberties-4132996 | + | The Middle East | middle-east-4132989 | + | Race Relations | race-relations-4132982 | + | Immigration | immigration-4132977 | + | Crime & Punishment | crime-and-punishment-4132972 | + | Canadian Government | canadian-government-4132959 | + | Understanding Types of Government | types-of-government-5179107 | + +#### English as a Second Language {#thoughtco-category-english-as-a-second-language} + + | category | id | + | ---------------------------- | ------------------------------------------ | + | Pronunciation & Conversation | esl-pronunciation-and-conversation-4133093 | + | Vocabulary | esl-vocabulary-4133092 | + | Writing Skills | esl-writing-skills-4133091 | + | Reading Comprehension | esl-reading-comprehension-4133090 | + | Grammar | esl-grammar-4133089 | + | Business English | esl-business-english-4133088 | + | Resources for Teachers | resources-for-esl-teachers-4133087 | + +#### Spanish {#thoughtco-category-spanish} + + | category | id | + | ----------------- | ----------------------------------- | + | History & Culture | spanish-history-and-culture-4133084 | + | Pronunciation | spanish-pronunciation-4133083 | + | Vocabulary | spanish-vocabulary-4133082 | + | Writing Skills | spanish-writing-skills-4133081 | + | Grammar | spanish-grammar-4133080 | + +#### French {#thoughtco-category-french} + + | category | id | + | ---------------------------- | -------------------------------------------- | + | Pronunciation & Conversation | french-pronunciation-4133075 | + | Vocabulary | french-vocabulary-4133076 | + | Grammar | french-grammar-4133074 | + | Resources For Teachers | french-resources-for-french-teachers-4133077 | + +#### German {#thoughtco-category-german} + + | category | id | + | ---------------------------- | ---------------------------------- | + | History & Culture | german-history-and-culture-4133071 | + | Pronunciation & Conversation | german-pronunciation-4133070 | + | Vocabulary | german-vocabulary-4133068 | + | Grammar | german-grammar-4133067 | + +#### Italian {#thoughtco-category-italian} + + | category | id | + | ----------------- | ----------------------------------- | + | History & Culture | italian-history-and-culture-4133065 | + | Vocabulary | italian-vocabulary-4133061 | + | Grammar | italian-grammar-4133063 | + +#### Japanese {#thoughtco-category-japanese} + + | category | id | + | ----------------------------- | ------------------------------------ | + | History & Culture | japanese-history-and-culture-4133058 | + | Essential Japanese Vocabulary | japanese-vocabulary-4133060 | + | Japanese Grammar | japanese-grammar-4133056 | + +#### Mandarin {#thoughtco-category-mandarin} + + | category | id | + | -------------------------------- | ---------------------------------------- | + | Mandarin History and Culture | mandarin-history-and-culture-4133054 | + | Pronunciation | mandarin-pronunciation-4133053 | + | Vocabulary | mandarin-vocabulary-4133052 | + | Understanding Chinese Characters | understanding-chinese-characters-4133051 | + +#### Russian {#thoughtco-category-russian} + + | category | id | + | -------- | --------------- | + | Russian | russian-4175265 | + +#### For Students & Parents {#thoughtco-category-for-students-parents} + + | category | id | + | ------------------ | -------------------------- | + | Homework Help | homework-help-4132587 | + | Private School | private-school-4132514 | + | Test Prep | test-prep-4132578 | + | College Admissions | college-admissions-4132565 | + | College Life | college-life-4132553 | + | Graduate School | graduate-school-4132543 | + | Business School | business-school-4132536 | + | Law School | law-school-4132527 | + | Distance Learning | distance-learning-4132521 | + +#### For Educators {#thoughtco-category-for-educators} + + | category | id | + | -------------------- | ----------------------------- | + | Becoming A Teacher | becoming-a-teacher-4132510 | + | Assessments & Tests | assessments-and-tests-4132508 | + | Elementary Education | elementary-education-4132507 | + | Secondary Education | secondary-education-4132504 | + | Special Education | special-education-4132499 | + | Teaching | teaching-4132488 | + | Homeschooling | homeschooling-4132480 | + +#### For Adult Learners {#thoughtco-category-for-adult-learners} + + | category | id | + | ----------------------- | ------------------------------- | + | Tips For Adult Students | tips-for-adult-students-4132468 | + | Getting Your Ged | getting-your-ged-4132466 | + +
+ +
+ ## Thrillist {#thrillist}