1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
const Feed = require('feed').Feed;
const express = require('express')
const request = require('request');
const app = express()
const port = 3000
function getFeed() {
const feed = new Feed({
title: "🍣YuWdのメモ🍣 - Scrapbox",
description: "🍣YuWdのメモ🍣",
id: "https://redirect.yuiga.dev/scrapbox/",
link: "https://redirect.yuiga.dev/scrapbox/",
language: "ja",
updated: new Date(Date.now()), // optional, default = today
author: {
name: "YuWd"
}
});
return feed;
}
app.get('/scrapbox/sitemap.xml', (req, res) => {
var options = {
url: "https://scrapbox.io/api/pages/yuwd?limit=500",
method: 'GET'
}
request(options, function (error, response, body) {
const jsonObject = JSON.parse(body);
const feed = getFeed();
jsonObject.pages.forEach((page) => {
const url = encodeURI("https://redirect.yuiga.dev/scrapbox/" + page.title);
feed.addItem({
title: page.title + " - 🍣YuWdのメモ🍣 - Scrapbox",
id: url,
link: url,
description: page.descriptions.join(" "),
date: new Date(page.updated),
image: page.image
});
});
res.send(feed.rss2());
})
})
app.get('/yuwd/sitemap.xml', (req, res) => {
var options = {
url: "https://yuiga.dev/blog/sitemap.xml",
method: 'GET'
}
request(options, function (error, response, body) {
body = body.replace(/https:\/\/yuiga.dev\/blog\//g, 'https://redirect.yuiga.dev/yuwd/')
res.send(body);
})
})
app.get(/\/scrapbox\/(.+)/, (req, res) => {
// Get Scrapbox title
const title = req.params[0];
// Redirect to Scrapbox
res.redirect(301, `https://scrapbox.io/yuwd/${encodeURIComponent(title)}`);
});
app.get(/\/yuwd\/(.+)/, (req, res) => {
var title = req.params[0];
title = encodeURIComponent(title);
title = title.replace(/%2F/g, '/');
res.redirect(301, `https://yuiga.dev/blog/${title}`);
});
app.listen(process.env.PORT || port, () => {
console.log(`Example app listening on port ${port}`)
})
|