Skip to content

Commit efbc5f9

Browse files
authored
chore: add reddit integration (#834)
* chore: add reddit integration * fix: addressing comments
1 parent 688ff08 commit efbc5f9

12 files changed

Lines changed: 287 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ const metascraper = require('metascraper')([
263263
- [metascraper-bluesky](https://github.com/microlinkhq/metascraper/tree/master/packages/metascraper-bluesky) – Metascraper integration for Bluesky.
264264
- [metascraper-dribbble](https://github.com/microlinkhq/metascraper/tree/master/packages/metascraper-dribbble) – Metascraper integration for Dribble.
265265
- [metascraper-instagram](https://github.com/microlinkhq/metascraper/tree/master/packages/metascraper-instagram) – Metascraper integration for Instagram.
266+
- [metascraper-reddit](https://github.com/microlinkhq/metascraper/tree/master/packages/metascraper-reddit) – Metascraper integration for Reddit.
266267
- [metascraper-soundcloud](https://github.com/microlinkhq/metascraper/tree/master/packages/metascraper-soundcloud) – Metascraper integration for SoundCloud.
267268
- [metascraper-spotify](https://github.com/microlinkhq/metascraper/tree/master/packages/metascraper-spotify) – Metascraper integration for Spotify.
268269
- [metascraper-telegram](https://github.com/microlinkhq/metascraper/tree/master/packages/metascraper-telegram) – Metascraper integration for Telegram.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@
220220
},
221221
"nano-staged": {
222222
"*.js": [
223+
"npx -y @kikobeats/prettier-standard",
223224
"standard --fix"
224225
],
225226
"package.json": [
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5+
6+
## [5.50.1](https://github.com/microlinkhq/metascraper/compare/v5.50.0...v5.50.1) (2026-04-24)
7+
8+
### Features
9+
10+
* **reddit:** add metascraper-reddit
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<div align="center">
2+
<br>
3+
<img style="width: 500px; margin:3rem 0 1.5rem;" src="https://metascraper.js.org/static/logo-banner.png" alt="metascraper">
4+
<br>
5+
<br>
6+
<p align="center"><strong>metascraper-reddit</strong>: Metascraper integration with Reddit.</p>
7+
<p align="center">See our <a href="https://metascraper.js.org" target='_blank' rel='noopener noreferrer'>website</a> for more information.</p>
8+
<br>
9+
</div>
10+
11+
## Install
12+
13+
```bash
14+
$ npm install metascraper-reddit --save
15+
```
16+
17+
## License
18+
19+
**metascraper-reddit** © [Microlink](https://microlink.io), released under the [MIT](https://github.com/microlinkhq/metascraper/blob/master/LICENSE.md) License.<br>
20+
Authored and maintained by [Microlink](https://microlink.io) with help from [contributors](https://github.com/microlinkhq/metascraper/contributors).
21+
22+
> [microlink.io](https://microlink.io) · GitHub [microlinkhq](https://github.com/microlinkhq) · X [@microlinkhq](https://x.com/microlinkhq)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "metascraper-reddit",
3+
"description": "Metascraper integration with Reddit",
4+
"homepage": "https://github.com/microlinkhq/metascraper/packages/metascraper-reddit",
5+
"version": "5.50.1",
6+
"types": "src/index.d.ts",
7+
"main": "src/index.js",
8+
"author": {
9+
"email": "hello@microlink.io",
10+
"name": "microlink.io",
11+
"url": "https://microlink.io"
12+
},
13+
"repository": {
14+
"directory": "packages/metascraper-reddit",
15+
"type": "git",
16+
"url": "git+https://github.com/microlinkhq/metascraper.git"
17+
},
18+
"bugs": {
19+
"url": "https://github.com/microlinkhq/metascraper/issues"
20+
},
21+
"keywords": [
22+
"metascraper",
23+
"reddit"
24+
],
25+
"dependencies": {
26+
"@metascraper/helpers": "workspace:*"
27+
},
28+
"devDependencies": {
29+
"ava": "5"
30+
},
31+
"engines": {
32+
"node": ">= 22"
33+
},
34+
"files": [
35+
"src"
36+
],
37+
"scripts": {
38+
"test": "NODE_PATH=.. TZ=UTC ava --timeout 15s"
39+
},
40+
"license": "MIT"
41+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare function rules(): import('metascraper').Rules;
2+
export = rules;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict'
2+
3+
const {
4+
description,
5+
image,
6+
memoizeOne,
7+
parseUrl,
8+
toRule,
9+
$filter,
10+
title
11+
} = require('@metascraper/helpers')
12+
13+
const toDescription = toRule(description)
14+
const toTitle = toRule(title)
15+
const toImage = toRule(image)
16+
17+
const REDDIT_DOMAINS = ['reddit.com', 'redd.it']
18+
19+
const test = memoizeOne(url => REDDIT_DOMAINS.includes(parseUrl(url).domain))
20+
21+
const previewUrl = url =>
22+
typeof url === 'string'
23+
? `https://s.microlink.io/?c=1&o1=ro&url=${encodeURIComponent(url)}`
24+
: undefined
25+
26+
module.exports = () => {
27+
const rules = {
28+
description: [
29+
toDescription($ => $('meta[name="description"]').attr('content'))
30+
],
31+
title: [toTitle($ => $filter($, $('title')))],
32+
image: [
33+
toImage($ => {
34+
const imageUrl = $('meta[property="og:image"]').attr('content')
35+
return imageUrl ? previewUrl(imageUrl) : undefined
36+
})
37+
],
38+
publisher: () => 'Reddit'
39+
}
40+
41+
rules.test = ({ url }) => test(url)
42+
43+
rules.pkgName = 'metascraper-reddit'
44+
45+
return rules
46+
}
47+
48+
module.exports.test = test
49+
module.exports.previewUrl = previewUrl
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
<!DOCTYPE html>
3+
<html lang="en-US" class="theme-beta minimal" dir="ltr" device="desktop">
4+
<head>
5+
<title>My Lotus Elise 72D with 17” Rays Volk GT-P : r/lotus</title>
6+
7+
<meta name="description"
8+
content="Just want to make a searchable Lotus Elise post with square wheels and staggered tires Volk GT-P. Just to give people ideas on filament. Square…">
9+
10+
<meta property="og:image"
11+
content="https://share.redd.it/preview/post/1pzbv0z"><meta
12+
property="og:image:width" content="1120"><meta property="og:image:height"
13+
content="584"><meta property="og:site_name" content="Reddit"><meta
14+
property="og:title"
15+
content="From the lotus community on Reddit: My Lotus Elise 72D with 17” Rays Volk GT-P"><meta
16+
property="og:ttl" content="600"><meta property="og:type"
17+
content="website"><meta property="og:url"
18+
content="https://www.reddit.com/r/lotus/comments/1pzbv0z/my_lotus_elise_72d_with_17_rays_volk_gtp/?seeker-session=true"><meta
19+
property="og:description"
20+
content="Explore this post and more from the lotus community"><meta
21+
property="og:image:alt"
22+
content="From the lotus community on Reddit: &quot;My Lotus Elise 72D with 17” Rays Volk GT-P&quot;"><meta
23+
name="twitter:card" content="summary_large_image"><meta
24+
name="twitter:image"
25+
content="https://share.redd.it/preview/post/1pzbv0z"><meta
26+
name="twitter:site" content="@reddit"><meta name="twitter:title"
27+
content="From the lotus community on Reddit: My Lotus Elise 72D with 17” Rays Volk GT-P">
28+
<meta name="robots" content="max-image-preview:large">
29+
30+
<link href="https://www.redditstatic.com/shreddit/assets/favicon/64x64.png"
31+
rel="icon shortcut" sizes="64x64">
32+
<link
33+
href="https://www.redditstatic.com/shreddit/assets/favicon/128x128.png"
34+
rel="icon shortcut" sizes="128x128">
35+
<link
36+
href="https://www.redditstatic.com/shreddit/assets/favicon/192x192.png"
37+
rel="icon shortcut" sizes="192x192">
38+
<link href="https://www.redditstatic.com/shreddit/assets/favicon/76x76.png"
39+
rel="apple-touch-icon" sizes="76x76">
40+
<link
41+
href="https://www.redditstatic.com/shreddit/assets/favicon/120x120.png"
42+
rel="apple-touch-icon" sizes="120x120">
43+
<link
44+
href="https://www.redditstatic.com/shreddit/assets/favicon/152x152.png"
45+
rel="apple-touch-icon" sizes="152x152">
46+
<link
47+
href="https://www.redditstatic.com/shreddit/assets/favicon/180x180.png"
48+
rel="apple-touch-icon" sizes="180x180">
49+
50+
<link rel="manifest"
51+
href="https://www.redditstatic.com/shreddit/assets/favicon/manifest.json">
52+
53+
</head>
54+
<body>
55+
</body>
56+
57+
</html>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict'
2+
3+
const { readFile } = require('fs/promises')
4+
const { resolve } = require('path')
5+
const test = require('ava')
6+
7+
const metascraperReddit = require('metascraper-reddit')
8+
9+
const createMetascraper = (...args) =>
10+
require('metascraper')([
11+
metascraperReddit(...args),
12+
require('metascraper-author')(),
13+
require('metascraper-date')(),
14+
require('metascraper-image')(),
15+
require('metascraper-description')(),
16+
require('metascraper-lang')(),
17+
require('metascraper-publisher')(),
18+
require('metascraper-title')(),
19+
require('metascraper-url')()
20+
])
21+
22+
test('from a post', async t => {
23+
const url =
24+
'https://www.reddit.com/r/lotus/comments/1pzbv0z/my_lotus_elise_72d_with_17_rays_volk_gtp/'
25+
const html = await readFile(resolve(__dirname, 'fixtures/post.html'))
26+
const metascraper = createMetascraper()
27+
const metadata = await metascraper({ url, html })
28+
t.snapshot(metadata)
29+
})
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Snapshot report for `test/index.js`
2+
3+
The actual snapshot is saved in `index.js.snap`.
4+
5+
Generated by [AVA](https://avajs.dev).
6+
7+
## from a post
8+
9+
> Snapshot 1
10+
11+
{
12+
author: null,
13+
date: null,
14+
description: 'Just want to make a searchable Lotus Elise post with square wheels and staggered tires Volk GT-P. Just to give people ideas on filament. Square…',
15+
image: 'https://s.microlink.io/?c=1&o1=ro&url=https%3A%2F%2Fshare.redd.it%2Fpreview%2Fpost%2F1pzbv0z',
16+
lang: 'en',
17+
publisher: 'Reddit',
18+
title: 'My Lotus Elise 72D with 17” Rays Volk GT-P : r/lotus',
19+
url: 'https://www.reddit.com/r/lotus/comments/1pzbv0z/my_lotus_elise_72d_with_17_rays_volk_gtp/?seeker-session=true',
20+
}

0 commit comments

Comments
 (0)