Google: 何がなんでも爆速でGoogle検索結果に載せる
redirectサーバはサブドメインでもOK
概要
とりあえず301を返してリダイレクトさせるようなリンクを作って, そいつらを登録したsitemapをgoogle search consoleに投げれば爆速でインデックス化してくれる
SEO対策というよりは, とりあえずインデックス化を促す感じ
外部からリンクが貼られてなくても, 内部リンクさえある程度あれば, ほぼ100%インデックス化されるはず
Heroku用に
process.env.PORT
が入ってるので注意
redirect.jsconst 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}`)
})