文章轉(zhuǎn)載: 自建 RSS 并通過 docker 部署網(wǎng)站地圖 | shmaur - shmaur
部署也是使用 docker
進(jìn)行部署审丘,對(duì)于相關(guān)的docker可以參考我其他文章:Docker
相關(guān)資料
下載RSSHub
源碼※
建議服務(wù)器與本地都進(jìn)行下載,可以先到本地修改完成后勾给,在將服務(wù)器上的文件替代就可以了滩报。
下載地址:dofy/RSSHub: ?? 萬物皆可 RSS (github.com)
開始自建源※
找到路徑 RSSHUB/lib/routes
文件夾锅知,建立你網(wǎng)站的名稱文件夾,并在下面建立一個(gè)index.ts
文件
我的idnex.ts
內(nèi)容
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,記錄產(chǎn)品脓钾,設(shè)計(jì)售睹,視覺設(shè)計(jì),技術(shù)開發(fā)可训,記錄生活昌妹;不積跬步無以至千里不積小流無以成江海",
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;
將服務(wù)器上面的文件全部替換上傳,全部完成后川蒙,創(chuàng)建一個(gè)新的鏡像※
回到RSSHUB
根目錄蚜厉,有dockerfile
文件目錄。執(zhí)行
[圖片上傳失敗...(image-8d6c0c-1717687718616)]
docker build -t shmaur/rss . # shmaur/rss 鏡像名字畜眨,不能有大寫, 后面必須要跟一個(gè)點(diǎn)术瓮,代表當(dāng)前目錄
[圖片上傳失敗...(image-84f8a5-1717687718616)]
鏡像制作完成后康聂,運(yùn)行容器即可※
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)]