文章转载: 自建 RSS 并通过 docker 部署网站地图 | shmaur - shmaur
部署也是使用 docker
进行部署,对于相关的docker可以参考我其他文章:Docker
相关资料
下载RSSHub
源码※
建议服务器与本地都进行下载,可以先到本地修改完成后,在将服务器上的文件替代就可以了。
下载地址:dofy/RSSHub: 🍰 万物皆可 RSS (github.com)
开始自建源※
找到路径 RSSHUB/lib/routes
文件夹,建立你网站的名称文件夹,并在下面建立一个index.ts
文件
我的idnex.ts
内容
import { Route } from '@/types';
import got from '@/utils/got';
import timezone from '@/utils/timezone';
import { load } from 'cheerio';
export const route: Route = {
path: '/',
radar: [
{
source: ['shmaur.com'],
target: '',
},
],
name: '黄金_shmaur',
maintainers: ['shmaur'],
handler,
url: 'shmaur.com',
};
async function handler() {
const currentUrl = 'https://www.shmaur.com';
const response = await got(currentUrl);
const $ = load(response.data);
const $articles = $('#blogItems');
const metaTags = $('meta');
const items = $articles
.map((_, el) => {
let textContent = "";
const title = $(el).find('#blogItemTitle').text().trim();
const link = $(el).find('a').attr('href');
const postDate = $(el).find('#blogPostDate').attr("blogpostdate");
const pubDate = timezone(new Date(postDate), +8);
const description = $(el).find('#blogItemSummary').text().trim();
$(el).find('#tagNameMeta').contents().each(function(e,va){
textContent +=' ' + $(va).text()
console.log(va)
})
const keywords = textContent
const category = $(el).find('#categoryMeta').text().trim();
const author = "shmaur"
return {
title,
description,
link,
pubDate,
keywords,
category,
author,
};
})
.toArray();
return {
title: '黄金_shmaur',
itunes_author:"shmaur",
itunes_category:"", //类别
description:"shmaur,记录产品,设计,视觉设计,技术开发,记录生活;不积跬步无以至千里不积小流无以成江海",
link: currentUrl,
item: items,
image:"https://www.shmaur.com/api/images/8cN7hKC0a7hq/logo.svg"
};
}
[图片上传失败...(image-2abf64-1717687718616)]
找到路径 RSSHUB/lib/router.js
,拉到最后添加
router.get('/shmaur', lazyloadRouteHandler('./routes/shmaur/index'));
找到路径RSSHUB/lib/views/rss.tsx
,我修改的东西比较多,全部贴上
import type { FC } from 'hono/jsx';
import { Data } from '@/types';
const RSS: FC<{ data: Data }> = ({ data }) => {
const hasItunes = data.itunes_author || data.itunes_category || (data.item && data.item.some((i) => i.itunes_item_image || i.itunes_duration));
const hasMedia = data.item?.some((i) => i.media);
return (
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes={hasItunes ? 'http://www.itunes.com/dtds/podcast-1.0.dtd' : undefined} xmlns:media={hasMedia ? 'http://search.yahoo.com/mrss/' : undefined} version="2.0">
<channel>
<title>{data.title || 'RSSHub'}</title>
<link>{data.link || 'https://docs.rsshub.app'}</link>
<atom:link href={data.atomlink} rel="self" type="application/rss+xml" />
<description>{data.description || data.title}</description>
<generator>RSSHub</generator>
<webMaster>shmaur@163.com (shmaur)</webMaster>
{data.itunes_author && <itunes:author>{data.itunes_author}</itunes:author>}
{data.itunes_category && <itunes:category text={data.itunes_category} />}
{data.itunes_author && <itunes:explicit>{data.itunes_explicit || 'false'}</itunes:explicit>}
<language>{data.language || 'en'}</language>
{data.image && (
<image>
<url>{data.image}</url>
<title>{data.title || 'RSSHub'}</title>
<link>{data.link}</link>
</image>
)}
<lastBuildDate>{data.lastBuildDate}</lastBuildDate>
<ttl>{data.ttl}</ttl>
{data.item?.map((item) => (
<item xmlns:media="http://www.w3.org/2005/Atom" xmlns:dcterms="http://purl.org/dc/terms/">
<title>{item.title}</title>
<media:title>{item.title}</media:title>
<description>{item.description}</description>
<media:description>{item.description}</media:description>
<link>{item.link}</link>
<media:keywords>{item.keywords}</media:keywords>
{typeof item.category === 'string' ? <media:category>{item.category}</media:category> : item.category?.map((c) => <media:category>{c}</media:category>)}
<guid isPermaLink="false">{item.guid || item.link || item.title}</guid>
{item.pubDate && <pubDate>{item.pubDate}</pubDate>}
{item.author && <author>{item.author}</author>}
{item.itunes_item_image && <itunes:image href={item.itunes_item_image} />}
{item.enclosure_url && <enclosure url={item.enclosure_url} length={item.enclosure_length} type={item.enclosure_type} />}
{item.itunes_duration && <itunes:duration>{item.itunes_duration}</itunes:duration>}
{typeof item.category === 'string' ? <category>{item.category}</category> : item.category?.map((c) => <category>{c}</category>)}
{item.media &&
Object.entries(item.media).map(([key, value]) => {
const Tag = `media:${key}`;
return <Tag {...value} />;
})}
</item>
))}
</channel>
</rss>
);
};
export default RSS;
将服务器上面的文件全部替换上传,全部完成后,创建一个新的镜像※
回到RSSHUB
根目录,有dockerfile
文件目录。执行
[图片上传失败...(image-8d6c0c-1717687718616)]
docker build -t shmaur/rss . # shmaur/rss 镜像名字,不能有大写, 后面必须要跟一个点,代表当前目录
[图片上传失败...(image-84f8a5-1717687718616)]
镜像制作完成后,运行容器即可※
docker run -d -p 1200:1200 shmaur/rss
[图片上传失败...(image-15f24b-1717687718616)]
[图片上传失败...(image-7a427a-1717687718616)]
然后代理一下就可以了※
location /shmaur {
proxy_pass http://127.0.0.1:1200/shmaur;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
}
看看效果※
[图片上传失败...(image-a7d53a-1717687718616)]