cb4decb672
- hugo.toml: ShowFullTextinRSS=true, [services.RSS] limit=5 - тема rDedInit rss.xml: prepend cover (figure.entry-cover, absURL) в content:encoded - openspec change rss-full-feed (план A реализован)
74 lines
2.6 KiB
Markdown
74 lines
2.6 KiB
Markdown
# Design: RSS Full Feed
|
||
|
||
## Overview
|
||
|
||
Включение полного текста и лимита RSS чисто конфигурационное (тема уже
|
||
поддерживает `content:encoded`). Меняем только `hugo.toml`.
|
||
|
||
## Changes
|
||
|
||
### 1. `hugo.toml` — добавить в `[params]`
|
||
|
||
```toml
|
||
# Полный текст постов в RSS (content:encoded)
|
||
ShowFullTextinRSS = true
|
||
```
|
||
|
||
### 2. `hugo.toml` — добавить секцию `[services.RSS]`
|
||
|
||
```toml
|
||
[services]
|
||
[services.RSS]
|
||
limit = 5
|
||
```
|
||
|
||
Примечание: в `hugo.toml` уже есть секция `[services]` с
|
||
`[services.googleAnalytics]` — добавим `[services.RSS]` рядом.
|
||
|
||
### 3. `themes/rDedInit/layouts/_default/rss.xml` — обложка в content:encoded
|
||
|
||
Перед `.Content` в `<content:encoded>` добавляется `figure.entry-cover` с
|
||
`<img>` обложки (абсолютный URL), если `cover.image` задан:
|
||
|
||
```go-html-template
|
||
{{- $coverHtml := "" }}
|
||
{{- with .Params.cover.image }}
|
||
{{- $coverAbs := (path.Join $.RelPermalink .) | absURL }}
|
||
{{- $coverHtml = printf "<figure class=\"entry-cover\"><img src=\"%s\" alt=\"%s\"></figure>" $coverAbs ($.Params.cover.alt | default $.Title | htmlEscape) }}
|
||
{{- end }}
|
||
<content:encoded>{{ (printf "<![CDATA[%s%s]]>" $coverHtml .Content) | safeHTML }}</content:encoded>
|
||
```
|
||
|
||
Примечание: тема — форк (rDedInit), правим её шаблон напрямую, т.к.
|
||
медиа-обложки рендерятся отдельным партиалом `cover.html` и в `.Content` не
|
||
попадают.
|
||
|
||
## Verification
|
||
|
||
```bash
|
||
cd /opt/dedinit.ru
|
||
hugo --minify # собрать
|
||
grep -c '<item>' public/index.xml # ожидаем 5
|
||
grep -c 'content:encoded' public/index.xml # ожидаем 5 (полный текст)
|
||
# проверить абсолютные медиа-ссылки в content:encoded:
|
||
python3 - <<'EOF'
|
||
import re
|
||
xml = open('public/index.xml', encoding='utf-8').read()
|
||
blocks = re.findall(r'<content:encoded><!\[CDATA\[(.*?)\]\]></content:encoded>', xml, re.S)
|
||
print('blocks:', len(blocks))
|
||
for i, b in enumerate(blocks[:2], 1):
|
||
urls = re.findall(r'https://dedinit\.ru/[^"\')\s]+', b)
|
||
print(i, 'media urls:', urls[:4])
|
||
EOF
|
||
```
|
||
|
||
## Rollback
|
||
|
||
Удалить из `hugo.toml`:
|
||
- строку `ShowFullTextinRSS = true`
|
||
- секцию `[services.RSS] limit = 5`
|
||
|
||
И откатить `themes/rDedInit/layouts/_default/rss.xml` (git checkout -- файл).
|
||
|
||
Пересобрать `hugo --minify`. Поведение вернётся к прежнему (все посты, без
|
||
полного текста). |