mirror of
https://github.com/yv1ing/MollyBlog.git
synced 2025-09-16 14:53:45 +08:00
new: Add RSS Feed
This commit is contained in:
@@ -1 +0,0 @@
|
||||
<h2 id="About-me">About me</h2>
|
||||
@@ -1,30 +0,0 @@
|
||||
<!--more-->
|
||||
<h1 id="Heading-level-1">Heading level 1</h1>
|
||||
<h2 id="Heading-level-2">Heading level 2</h2>
|
||||
<h3 id="Heading-level-3">Heading level 3</h3>
|
||||
<h4 id="Heading-level-4">Heading level 4</h4>
|
||||
<h5 id="Heading-level-5">Heading level 5</h5>
|
||||
<h6 id="Heading-level-6">Heading level 6</h6>
|
||||
<p>I just love <strong>bold text</strong>.</p>
|
||||
<blockquote>
|
||||
<p>Dorothy followed her through many of the beautiful rooms in her castle.</p>
|
||||
</blockquote>
|
||||
<ol>
|
||||
<li>First item</li>
|
||||
<li>Second item</li>
|
||||
<li>Third item</li>
|
||||
<li>Fourth item</li>
|
||||
</ol>
|
||||
<ul>
|
||||
<li>First item</li>
|
||||
<li>Second item</li>
|
||||
<li>Third item</li>
|
||||
<li>Fourth item</li>
|
||||
</ul>
|
||||
<pre><code class="language-go highlight-chroma"><span class="highlight-line"><span class="highlight-cl"><span class="highlight-kd">func</span> <span class="highlight-nf">main</span><span class="highlight-p">()</span> <span class="highlight-p">{</span>
|
||||
</span></span><span class="highlight-line"><span class="highlight-cl"> <span class="highlight-nx">fmt</span><span class="highlight-p">.</span><span class="highlight-nf">Println</span><span class="highlight-p">(</span><span class="highlight-s">"Hello, World"</span><span class="highlight-p">)</span>
|
||||
</span></span><span class="highlight-line"><span class="highlight-cl"><span class="highlight-p">}</span>
|
||||
</span></span></code></pre>
|
||||
<hr />
|
||||
<p>This is a link: <a href="https://markdown.com.cn">Markdown link</a>。</p>
|
||||
<p><img src="https://markdown.com.cn/assets/img/philly-magic-garden.9c0b4415.jpg" alt="Image" title="Magic Gardens" /></p>
|
||||
@@ -1,2 +0,0 @@
|
||||
## About me
|
||||
|
||||
10
config.yaml
10
config.yaml
@@ -9,8 +9,8 @@ update_secret: 123456
|
||||
|
||||
# configure object storage to automatically obtain article updates
|
||||
storage:
|
||||
src: _blog/src/post
|
||||
dst: _blog/dst/post
|
||||
src: _blog/post/src
|
||||
dst: _blog/post/dst
|
||||
auto_pull: true
|
||||
type: COS
|
||||
cos:
|
||||
@@ -29,6 +29,7 @@ site:
|
||||
# basic info
|
||||
info:
|
||||
logo: /assets/img/logo.png
|
||||
link: https://blog.yvling.cn
|
||||
motto:
|
||||
- I hope I can make it out of here.
|
||||
- I hope that I can still feel the sun on my face, and hear the sound of the rain.
|
||||
@@ -39,8 +40,10 @@ site:
|
||||
- —— Andy Dufresne
|
||||
title: Molly Blog
|
||||
author: yvling
|
||||
email: yvling.cn@outlook.com
|
||||
language: en
|
||||
copyright: Copyright © 2024 Powered by <a href="https://github.com/yv1ing/MollyBlog">MollyBlog</a>
|
||||
description: A simple and easy-to-use blog
|
||||
|
||||
# menu config
|
||||
menu:
|
||||
@@ -54,6 +57,9 @@ site:
|
||||
- name: About
|
||||
icon: fa-solid fa-circle-info
|
||||
url: /about
|
||||
- name: RSS
|
||||
icon: fa-solid fa-rss
|
||||
url: /rss
|
||||
|
||||
# post config
|
||||
post:
|
||||
|
||||
@@ -2,10 +2,13 @@ package config
|
||||
|
||||
type mInfo struct {
|
||||
Logo string `yaml:"logo"`
|
||||
Link string `yaml:"link"`
|
||||
Title string `yaml:"title"`
|
||||
Author string `yaml:"author"`
|
||||
Email string `yaml:"email"`
|
||||
Language string `yaml:"language"`
|
||||
Copyright string `yaml:"copyright"`
|
||||
Description string `yaml:"description"`
|
||||
|
||||
Motto []string `yaml:"motto"`
|
||||
}
|
||||
|
||||
1
go.mod
1
go.mod
@@ -5,6 +5,7 @@ go 1.23
|
||||
require (
|
||||
github.com/88250/lute v1.7.6
|
||||
github.com/gin-gonic/gin v1.10.0
|
||||
github.com/gorilla/feeds v1.2.0
|
||||
github.com/huichen/wukong v0.0.0-20210824074240-ecbd39fa0b56
|
||||
github.com/tencentyun/cos-go-sdk-v5 v0.7.59
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
|
||||
8
go.sum
8
go.sum
@@ -68,6 +68,8 @@ github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
|
||||
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
|
||||
github.com/gorilla/feeds v1.2.0 h1:O6pBiXJ5JHhPvqy53NsjKOThq+dNFm8+DFrxBEdzSCc=
|
||||
github.com/gorilla/feeds v1.2.0/go.mod h1:WMib8uJP3BbY+X8Szd1rA5Pzhdfh+HCCAYT2z7Fza6Y=
|
||||
github.com/huichen/murmur v0.0.0-20130808212358-e0489551cf51 h1:86ZSBmeBzG7dWW2rx9imn5pVKgqe7YjWzZ9qhn4Z+9A=
|
||||
github.com/huichen/murmur v0.0.0-20130808212358-e0489551cf51/go.mod h1:UKrDR4kaPWAPk8cJGrHoTgyI8OmHPNDjUxx/aOK4ySU=
|
||||
github.com/huichen/sego v0.0.0-20210824061530-c87651ea5c76 h1:qNQ2+1IQT9Mor/vfEHePOQSbiapLoNI7sQmpxM7l1Ew=
|
||||
@@ -82,6 +84,10 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
|
||||
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
|
||||
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
|
||||
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
@@ -101,6 +107,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
|
||||
@@ -23,6 +23,8 @@ type MApp struct {
|
||||
engine *gin.Engine
|
||||
searcher *engine.Engine
|
||||
|
||||
RSS string
|
||||
|
||||
Posts []*model.MPost
|
||||
IndexedPosts map[uint64]*model.MPost
|
||||
|
||||
|
||||
@@ -457,6 +457,9 @@ func (ma *MApp) UpdateBlogHandler(ctx *gin.Context) {
|
||||
// parse post index
|
||||
ma.loadPostIndex()
|
||||
|
||||
// parse rss
|
||||
ma.RSS = ma.generateRSS()
|
||||
|
||||
log.Println("update blog success")
|
||||
ctx.JSON(http.StatusOK, gin.H{"msg": "ok"})
|
||||
}
|
||||
@@ -485,3 +488,11 @@ func (ma *MApp) AboutHandler(ctx *gin.Context) {
|
||||
|
||||
ctx.HTML(http.StatusOK, "about.html", resData)
|
||||
}
|
||||
|
||||
func (ma *MApp) RSSHandler(ctx *gin.Context) {
|
||||
if ma.RSS != "" {
|
||||
ctx.String(http.StatusOK, ma.RSS)
|
||||
} else {
|
||||
ctx.String(http.StatusNotFound, "RSS Not Found")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ func (ma *MApp) loadRoutes() {
|
||||
ma.engine.Use(ma.AuthMiddleware)
|
||||
|
||||
ma.engine.GET("/", ma.IndexHandler)
|
||||
ma.engine.GET("/rss", ma.RSSHandler)
|
||||
ma.engine.GET("/about", ma.AboutHandler)
|
||||
ma.engine.GET("/search", ma.SearchHandler)
|
||||
ma.engine.GET("/archive", ma.ArchiveHandler)
|
||||
|
||||
56
internal/mApp/mRss.go
Normal file
56
internal/mApp/mRss.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package mApp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/feeds"
|
||||
)
|
||||
|
||||
func (ma *MApp) generateRSS() string {
|
||||
layout := "2006-01-02 15:04:05"
|
||||
now := time.Now()
|
||||
|
||||
feed := &feeds.Feed{
|
||||
Created: now,
|
||||
Title: ma.Config.MSite.Info.Title,
|
||||
Link: &feeds.Link{Href: ma.Config.MSite.Info.Link},
|
||||
Author: &feeds.Author{Name: ma.Config.MSite.Info.Author, Email: ma.Config.MSite.Info.Email},
|
||||
Description: ma.Config.MSite.Info.Description,
|
||||
}
|
||||
|
||||
count := 0
|
||||
var items []*feeds.Item
|
||||
for _, post := range ma.Posts {
|
||||
if count >= ma.Config.MSite.Post.RecentPost.Number {
|
||||
break
|
||||
}
|
||||
|
||||
updated, err := time.Parse(layout, post.Date)
|
||||
if err != nil {
|
||||
log.Println("Error parsing updated time ", post.Date)
|
||||
continue
|
||||
}
|
||||
|
||||
item := &feeds.Item{
|
||||
Title: post.Title,
|
||||
Id: strconv.FormatUint(post.Index, 10),
|
||||
Link: &feeds.Link{Href: fmt.Sprintf("%s/post/%s", ma.Config.MSite.Info.Link, post.HtmlHash)},
|
||||
Author: &feeds.Author{Name: ma.Config.MSite.Info.Author, Email: ma.Config.MSite.Info.Email},
|
||||
Updated: updated,
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
count++
|
||||
}
|
||||
|
||||
feed.Items = items
|
||||
rss, err := feed.ToRss()
|
||||
if err != nil {
|
||||
log.Println("Error generating rss ", err)
|
||||
}
|
||||
|
||||
return rss
|
||||
}
|
||||
Reference in New Issue
Block a user