皆さんこんにちは。Sandyマンです。Hugoのindex.xmlに一部記事が登録されないようにしてみたので方法を残そうと思います。
結論
rss.xmlのここを変える。
1{{- $pctx := . -}}
2{{- if .IsHome -}}{{ $pctx = site }}{{- end -}}
3{{- $pages := slice -}}
4{{- if or $.IsHome $.IsSection -}}
5{{- $pages = $pctx.RegularPages -}}
6{{- else -}}
7{{- $pages = $pctx.Pages -}}
8{{- end -}}
9{{- $limit := site.Config.Services.RSS.Limit -}}
10{{- if ge $limit 1 -}}
11{{- $pages = $pages | first $limit -}}
12{{- end -}}
13{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
14
15<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
16 <channel>
17 <title>{{ if eq .Title site.Title }}{{ site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ site.Title }}{{ end }}</title>
18 <link>{{ .Permalink }}</link>
19 <description>Recent content {{ if ne .Title site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ site.Title }}</description>
20 {{- with site.Params.images }}
21 <image>
22 <title>{{ site.Title }}</title>
23 <url>{{ index . 0 | absURL }}</url>
24 <link>{{ index . 0 | absURL }}</link>
25 </image>
26 {{- end }}
27 <generator>Hugo -- gohugo.io</generator>{{ with site.LanguageCode }}
28 <language>{{.}}</language>{{end}}{{ with site.Author.email }}
29 <managingEditor>{{.}}{{ with site.Author.name }} ({{.}}){{end}}</managingEditor>{{end}}{{ with site.Author.email }}
30 <webMaster>{{.}}{{ with site.Author.name }} ({{.}}){{end}}</webMaster>{{end}}{{ with site.Copyright }}
31 <copyright>{{.}}</copyright>{{end}}{{ if not .Date.IsZero }}
32 <lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
33 {{- with .OutputFormats.Get "RSS" -}}
34 {{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
35 {{- end -}}
36 {{ range $pages }}
37- {{- if and (ne .Layout `search`) (ne .Layout `archives`) }}
38+ {{- if and (ne .Layout `search`) (ne .Layout `archives`) (not (strings.Contains .Permalink "/scraps/")) }}
39 <item>
40 <title>{{ .Title }}</title>
41 <link>{{ .Permalink }}</link>
42 <pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
43 {{ with site.Author.email }}<author>{{.}}{{ with site.Author.name }} ({{.}}){{end}}</author>{{end}}
44 <guid>{{ .Permalink }}</guid>
45 <description>{{ with .Description | html }}{{ . }}{{ else }}{{ .Summary | html }}{{ end -}}</description>
46 {{- if site.Params.ShowFullTextinRSS }}
47 <content:encoded>{{ (printf "<![CDATA[%s]]>" .Content) | safeHTML }}</content:encoded>
48 {{- end }}
49 </item>
50 {{- end }}
51 {{ end }}
52 </channel>
53</rss>-のところを消して、代わりに+のところを記述してあげるといい感じになります。この場合だと、/scraps/が登録されないようになります。
まとめ
ということで、Hugoで一部記事が登録されないようにしてみました。それではさようならーーーーーーーー!