This commit is contained in:
deepzz0
2016-11-15 01:51:23 +08:00
parent d84abc2719
commit a6d2f7796e
10 changed files with 128 additions and 43 deletions

2
api.go
View File

@@ -211,6 +211,7 @@ func apiPostAdd(c *gin.Context) {
cid = int(artc.ID)
if publish {
ElasticIndex(artc)
DoPings(slug)
}
return
}
@@ -248,6 +249,7 @@ func apiPostAdd(c *gin.Context) {
GenerateExcerptAndRender(artc)
// elasticsearch 索引
ElasticIndex(artc)
DoPings(slug)
if artc.ID >= setting.Conf.StartID {
ManageTagsArticle(artc, true, ADD)
ManageSeriesArticle(artc, true, ADD)

View File

@@ -16,8 +16,6 @@ identifier: <!--more-->
startid: 11
# elasticsearch url
searchurl: http://elasticsearch:9200
# superfeedr shortname
superfeedr: deepzz
# 评论相关
disqus:
shortname: deepzz
@@ -53,6 +51,14 @@ mode:
domain: deepzz.com
# twitter地址: twitter.com/chenqijing2
twitter: twitter.com/chenqijing2
# superfeedr url
feedrurl: https://deepzz.superfeedr.com/
# ping rpcs 地址
pingrpcs:
- http://ping.baidu.com/ping/RPC2
- http://blogsearch.google.com/ping/RPC2
- http://rpc.pingomatic.com/
# 以下数据初始化用,可在后台修改
account:
# *后台登录用户名

View File

@@ -126,7 +126,7 @@ server {
proxy_hide_header Vary;
proxy_hide_header X-Powered-By;
# proxy_set_header X-Via QingDao.Aliyun;
proxy_set_header X-Via QingDao.Aliyun;
proxy_set_header Connection "";
proxy_set_header Host deepzz.com;
proxy_set_header X-Real_IP $remote_addr;

View File

@@ -5,7 +5,7 @@
<link>https://{{.Domain}}</link>
<description>{{.SubTitle}}</description>
<atom:link href="https://{{.Domain}}/rss.html" rel="self"/>
<atom:link href="https://{{.Superfeedr}}.superfeedr.com/" rel="hub"/>
<atom:link href="{{.FeedrURL}}" rel="hub"/>
<language>zh-CN</language>
<lastBuildDate>{{.BuildDate}}</lastBuildDate>
{{range .Artcs}}

9
glide.lock generated
View File

@@ -1,12 +1,12 @@
hash: 4b70e76a2e830e97033c06d0e5a90c3199985ff5070bdf8364b1feca63d5caa5
updated: 2016-11-12T02:35:12.289411301+08:00
updated: 2016-11-14T22:09:13.900837801+08:00
imports:
- name: github.com/boj/redistore
version: fc113767cd6b051980f260d6dbe84b2740c46ab0
- name: github.com/eiblog/blackfriday
version: c0ec111761ae784fe31cc076f2fa0e2d2216d623
- name: github.com/eiblog/utils
version: 9ae244bfa2feec3e339a26190a56093fde200288
version: 3352fddbea01fcfeeb8d903b72f3b84da9780525
subpackages:
- logd
- mgo
@@ -61,8 +61,11 @@ imports:
- api
- auth/qbox
- conf
- kodo
- kodocli
- name: qiniupkg.com/api.v7/conf
version: ad7023b87b2f5c169812da49fe44900be1c4e5c2
- name: qiniupkg.com/api.v7/kodo
version: ad7023b87b2f5c169812da49fe44900be1c4e5c2
- name: qiniupkg.com/x
version: f512abcf45ab4e2ba0fd4784c57b53d495997d66
subpackages:

84
ping.go
View File

@@ -1,30 +1,29 @@
package main
import (
"bytes"
"encoding/xml"
"io/ioutil"
"net/http"
"net/url"
"github.com/eiblog/eiblog/setting"
"github.com/eiblog/utils/logd"
)
type Feeder interface {
type Pinger interface {
PingFunc(url string)
}
// superfeedr
// http://<your-hub-name>.superfeedr.com/
type Superfeedr struct {
URL string
}
type superfeedr struct{}
func (f *Superfeedr) PingFunc(urls ...string) {
func (_ *superfeedr) PingFunc(slug string) {
vals := url.Values{}
vals.Set("hub.mode", "publish")
for _, u := range urls {
vals.Add("hub.url", u)
}
res, err := http.PostForm(f.URL, vals)
vals.Add("hub.url", "https://"+setting.Conf.Mode.Domain+"/post/"+slug+".html")
res, err := http.PostForm(setting.Conf.FeedrURL, vals)
if err != nil {
logd.Error(err)
return
@@ -39,3 +38,70 @@ func (f *Superfeedr) PingFunc(urls ...string) {
logd.Error(string(data))
}
}
// google baidu
// params
// BlogName string `xml:"param>value>string"`
// HomePage string `xml:"param>value>string"`
// Article string `xml:"param>value>string"`
// RSS_URL string `xml:"param>value>string"`
type pingRPC struct {
XMLName xml.Name `xml:"methodCall"`
MethodName string `xml:"methodName"`
Params struct {
Param [4]rpcValue `xml:"param"`
} `xml:"params"`
}
type rpcValue struct {
Value string `xml:"value>string"`
}
func (p *pingRPC) PingFunc(slug string) {
p.Params.Param[1].Value = "https://" + setting.Conf.Mode.Domain + "/post/" + slug + ".html"
buf := &bytes.Buffer{}
buf.WriteString(xml.Header)
enc := xml.NewEncoder(buf)
if err := enc.Encode(p); err != nil {
logd.Error(err)
return
}
for _, url := range setting.Conf.PingRPCs {
rep, err := http.Post(url, "text/xml", buf)
if err != nil {
logd.Error(err)
continue
}
defer rep.Body.Close()
data, err := ioutil.ReadAll(rep.Body)
if err != nil {
logd.Error(err)
continue
}
logd.Print(string(data))
if rep.StatusCode != 200 {
logd.Error(string(data))
continue
}
}
}
var Pings []Pinger
func init() {
Pings = append(Pings, &superfeedr{})
pr := &pingRPC{MethodName: "weblogUpdates.extendedPing"}
pr.Params.Param = [4]rpcValue{
0: rpcValue{Value: Ei.BTitle},
1: rpcValue{Value: "https://" + setting.Conf.Mode.Domain},
2: rpcValue{},
3: rpcValue{Value: "https://" + setting.Conf.Mode.Domain + "/rss.html"},
}
Pings = append(Pings, pr)
}
func DoPings(slug string) {
for _, p := range Pings {
go p.PingFunc(slug)
}
}

View File

@@ -2,13 +2,25 @@
package main
import (
"fmt"
"testing"
"github.com/eiblog/eiblog/setting"
)
func TestPing(t *testing.T) {
sf := Superfeedr{URL: fmt.Sprintf("https://%s.superfeedr.com", setting.Conf.Superfeedr)}
func TestSuperFeedr(t *testing.T) {
sf := superfeedr{}
sf.PingFunc("https://deepzz.com/rss.html")
}
func TestPingRPC(t *testing.T) {
pr := pingRPC{
MethodName: "weblogUpdates.extendedPing",
}
pr.Params.Param = [4]rpcValue{
rpcValue{Value: Ei.BTitle},
rpcValue{Value: "https://" + setting.Conf.Mode.Domain},
rpcValue{Value: "https://deepzz.com/post/gdb-debug.html"},
rpcValue{Value: "https://deepzz.com/rss.html"},
}
pr.PingFunc("https://deepzz.com/post/gdb-debug.html")
}

View File

@@ -3,8 +3,6 @@ package setting
import (
"io/ioutil"
"os"
"path"
"github.com/eiblog/utils/logd"
"gopkg.in/yaml.v2"
@@ -16,7 +14,6 @@ const (
)
var (
wd, _ = os.Getwd()
Conf = new(Config)
BlackIP = make(map[string]bool)
)
@@ -32,9 +29,7 @@ type Config struct {
Identifier string // 截取标示
Favicon string // icon地址
StartID int32 // 文章起始id
Static string // cdn地址
SearchURL string // elasticsearch 地址
Superfeedr string // superfeedr
Disqus struct { // 获取文章数量相关
ShortName string
PublicKey string
@@ -54,8 +49,17 @@ type Config struct {
AccessKey string
SecretKey string
}
Mode RunMode // 运行模式
Twitter string // twitter地址
Mode RunMode // 运行模式
Twitter string // twitter地址
FeedrURL string // superfeedr url
PingRPCs []string // ping rpc 地址
Account struct {
Username string // *
Password string // *
Email string
PhoneNumber string
Address string
}
Blogger struct { // 初始化数据
BlogName string
SubTitle string
@@ -63,13 +67,6 @@ type Config struct {
BTitle string
Copyright string
}
Account struct {
Username string // *
Password string // *
Email string
PhoneNumber string
Address string
}
}
type RunMode struct {
@@ -84,13 +81,12 @@ type RunMode struct {
func init() {
// 初始化配置
dir := wd + "/conf"
data, err := ioutil.ReadFile(path.Join(dir, "app.yml"))
data, err := ioutil.ReadFile("conf/app.yml")
checkError(err)
err = yaml.Unmarshal(data, Conf)
checkError(err)
data, err = ioutil.ReadFile(path.Join(dir, "blackip.yml"))
data, err = ioutil.ReadFile("conf/blackip.yml")
checkError(err)
err = yaml.Unmarshal(data, BlackIP)
checkError(err)

View File

@@ -1 +1 @@
{{define "article"}}<div id=content class=inner>{{with .Article}}<article class="post post-{{.ID}}" itemscope itemtype="http://schema.org/Article"><div class=meta><div class=date><time itemprop=datePublished content="{{dateformat .CreateTime " 2006-01-02 "}}">{{dateformat .CreateTime "Jan 02, 2006"}}</time></div><div class=comment><a href="#comments">{{.Count}} Comments</a></div></div><h1 class=title itemprop=headline>{{.Title}}</h1><div class="entry-content" itemprop=articleBody>{{str2html .Header}}{{str2html .Content}}<p>本文链接:<a rel="bookmark" title="Permalink to {{.Title}}" href="//{{$.Domain}}/post/{{.Slug}}.html" itemprop="url">https://{{$.Domain}}/post/{{.Slug}}.html</a><a href="//{{$.Domain}}/post/{{.Slug}}.html#comments">参与评论 »</a></p><p>--<acronym title="End of File">EOF</acronym>--</p><p class="post-info">发表于 <span class="date">{{dateformat .CreateTime "2006-01-02 15:04:05"}}</span>{{if gt (.Tags|len) 0}},并被添加「{{range $index, $elem := .Tags}}{{if gt $index 0}}、{{end}}<a href="/search.html?q=tag:{{$elem}}">{{$elem}}</a>{{end}}」标签{{end}}{{if .UpdateTime|isnotzero}},最后修改于 <span class="date">{{dateformat .UpdateTime "2006-01-02 15:04:05"}}</span>{{end}}。</p>{{with $.Copyright}}<p class="copyright-info">{{str2html $.Copyright}}<a href="//{{$.Domain}}/post/about.html#toc-1">更多说明 »</a></p>{{end}}{{if gt $.Days 100}}<p class="expire-tips">提醒:本文最后更新于 {{$.Days}} 天前,文中所描述的信息可能已发生改变,请谨慎使用。</p>{{end}}{{with $.Serie}}<div class="entry-series"><h3>专题「{{.Name}}」的其它文章 <a href="/series.html#toc-{{.ID}}" title="更多">»</a></h3><ul>{{range .Articles}}{{if ne .ID $.Article.ID}}<li><a href="/post/{{.Slug}}.html">{{.Title}}</a> <span class="date">({{dateformat .CreateTime "Jan 02, 2006"}})</span></li>{{end}}{{end}}</ul></div>{{end}}</div></article><nav class="page-navi">{{with .Prev}}<a href="/post/{{.Slug}}.html" class=prev>« {{.Title}}</a>{{end}}{{with .Next}}<a href="/post/{{.Slug}}.html" class=next>{{.Title}} »</a>{{end}}</nav><section id=comments><h1 class=title>Comments<span id=switch_thread_mode></h1><div id=disqus_thread class=ds-thread data-identifier="post-{{.Slug}}" data-url="https://{{$.Domain}}/post/{{.Slug}}.html"></div><div id=simple_thread data-id="{{.Slug}}"></div></section>{{end}}</div>{{end}}
{{define "article"}}<div id=content class=inner>{{with .Article}}<article class="post post-{{.ID}}" itemscope itemtype="http://schema.org/Article"><div class=meta><div class=date><time itemprop=datePublished content="{{dateformat .CreateTime "2006-01-02"}}">{{dateformat .CreateTime "Jan 02, 2006"}}</time></div><div class=comment><a href="#comments">{{.Count}} Comments</a></div></div><h1 class=title itemprop=headline>{{.Title}}</h1><div class="entry-content" itemprop=articleBody>{{str2html .Header}}{{str2html .Content}}<p>本文链接:<a rel="bookmark" title="Permalink to {{.Title}}" href="//{{$.Domain}}/post/{{.Slug}}.html" itemprop="url">https://{{$.Domain}}/post/{{.Slug}}.html</a><a href="//{{$.Domain}}/post/{{.Slug}}.html#comments">参与评论 »</a></p><p>--<acronym title="End of File">EOF</acronym>--</p><p class="post-info">发表于 <span class="date">{{dateformat .CreateTime "2006-01-02 15:04:05"}}</span>{{if gt (.Tags|len) 0}},并被添加「{{range $index, $elem := .Tags}}{{if gt $index 0}}、{{end}}<a href="/search.html?q=tag:{{$elem}}">{{$elem}}</a>{{end}}」标签{{end}}{{if .UpdateTime|isnotzero}},最后修改于 <span class="date">{{dateformat .UpdateTime "2006-01-02 15:04:05"}}</span>{{end}}。</p>{{with $.Copyright}}<p class="copyright-info">{{str2html $.Copyright}}<a href="//{{$.Domain}}/post/about.html#toc-1">更多说明 »</a></p>{{end}}{{if gt $.Days 100}}<p class="expire-tips">提醒:本文最后更新于 {{$.Days}} 天前,文中所描述的信息可能已发生改变,请谨慎使用。</p>{{end}}{{with $.Serie}}<div class="entry-series"><h3>专题「{{.Name}}」的其它文章 <a href="/series.html#toc-{{.ID}}" title="更多">»</a></h3><ul>{{range .Articles}}{{if ne .ID $.Article.ID}}<li><a href="/post/{{.Slug}}.html">{{.Title}}</a> <span class="date">({{dateformat .CreateTime "Jan 02, 2006"}})</span></li>{{end}}{{end}}</ul></div>{{end}}</div></article><nav class="page-navi">{{with .Prev}}<a href="/post/{{.Slug}}.html" class=prev>« {{.Title}}</a>{{end}}{{with .Next}}<a href="/post/{{.Slug}}.html" class=next>{{.Title}} »</a>{{end}}</nav><section id=comments><h1 class=title>Comments<span id=switch_thread_mode></h1><div id=disqus_thread class=ds-thread data-identifier="post-{{.Slug}}" data-url="https://{{$.Domain}}/post/{{.Slug}}.html"></div><div id=simple_thread data-id="{{.Slug}}"></div></section>{{end}}</div>{{end}}

12
xml.go
View File

@@ -39,12 +39,12 @@ func doFeed() {
_, _, artcs := PageList(1, FEED_COUNT)
buildDate := time.Now()
params := map[string]interface{}{
"Title": Ei.BTitle,
"SubTitle": Ei.SubTitle,
"Domain": setting.Conf.Mode.Domain,
"Superfeedr": setting.Conf.Superfeedr,
"BuildDate": buildDate.Format(time.RFC1123Z),
"Artcs": artcs,
"Title": Ei.BTitle,
"SubTitle": Ei.SubTitle,
"Domain": setting.Conf.Mode.Domain,
"FeedrURL": setting.Conf.FeedrURL,
"BuildDate": buildDate.Format(time.RFC1123Z),
"Artcs": artcs,
}
f, err := os.OpenFile("static/feed.xml", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm)