mirror of
https://github.com/venthur/blag.git
synced 2025-11-25 20:52:43 +00:00
Use description tag for Atom feed if provided
This commit is contained in:
25
blag/blag.py
25
blag/blag.py
@@ -243,6 +243,25 @@ def generate_feed(
|
||||
blog_description,
|
||||
blog_author,
|
||||
):
|
||||
"""Generate Atom feed.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
articles : list[list[str, dict]]
|
||||
list of relative output path and article dictionary
|
||||
output_dir : str
|
||||
where the feed is stored
|
||||
base_url : str
|
||||
base url
|
||||
blog_title : str
|
||||
blog title
|
||||
blog_description : str
|
||||
blog description
|
||||
blog_author : str
|
||||
blog author
|
||||
|
||||
"""
|
||||
logger.info('Generating Atom feed.')
|
||||
feed = feedgenerator.Atom1Feed(
|
||||
link=base_url,
|
||||
title=blog_title,
|
||||
@@ -251,11 +270,15 @@ def generate_feed(
|
||||
)
|
||||
|
||||
for dst, context in articles:
|
||||
# if article has a description, use that. otherwise fall back to
|
||||
# the title
|
||||
description = context.get('description', context['title'])
|
||||
|
||||
feed.add_item(
|
||||
title=context['title'],
|
||||
author_name=blog_author,
|
||||
link=base_url + dst,
|
||||
description=context['title'],
|
||||
description=description,
|
||||
content=context['content'],
|
||||
pubdate=context['date'],
|
||||
)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from tempfile import TemporaryDirectory
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -18,6 +19,76 @@ def test_generate_feed(outdir):
|
||||
assert os.path.exists(f'{outdir}/atom.xml')
|
||||
|
||||
|
||||
def test_feed(outdir):
|
||||
articles = [
|
||||
[
|
||||
'dest1.html',
|
||||
{
|
||||
'title': 'title1',
|
||||
'date': datetime(2019, 6, 6),
|
||||
'content': 'content1',
|
||||
}
|
||||
],
|
||||
[
|
||||
'dest2.html',
|
||||
{
|
||||
'title': 'title2',
|
||||
'date': datetime(1980, 5, 9),
|
||||
'content': 'content2',
|
||||
}
|
||||
],
|
||||
|
||||
]
|
||||
|
||||
blag.generate_feed(articles, outdir, 'https://example.com/', 'blog title',
|
||||
'blog description', 'blog author')
|
||||
with open(f'{outdir}/atom.xml') as fh:
|
||||
feed = fh.read()
|
||||
|
||||
assert '<title>blog title</title>' in feed
|
||||
# enable when https://github.com/getpelican/feedgenerator/issues/22
|
||||
# is fixed
|
||||
# assert '<subtitle>blog description</subtitle>' in feed
|
||||
assert '<author><name>blog author</name></author>' in feed
|
||||
|
||||
# article 1
|
||||
assert '<title>title1</title>' in feed
|
||||
assert '<summary type="html">title1' in feed
|
||||
assert '<published>2019-06-06' in feed
|
||||
assert '<content type="html">content1' in feed
|
||||
assert '<link href="https://example.com/dest1.html"' in feed
|
||||
|
||||
# article 2
|
||||
assert '<title>title2</title>' in feed
|
||||
assert '<summary type="html">title2' in feed
|
||||
assert '<published>1980-05-09' in feed
|
||||
assert '<content type="html">content2' in feed
|
||||
assert '<link href="https://example.com/dest2.html"' in feed
|
||||
|
||||
|
||||
def test_generate_feed_with_description(outdir):
|
||||
# if a description is provided, it will be used as the summary in
|
||||
# the feed, otherwise we simply use the title of the article
|
||||
articles = [[
|
||||
'dest.html',
|
||||
{
|
||||
'title': 'title',
|
||||
'description': 'description',
|
||||
'date': datetime(2019, 6, 6),
|
||||
'content': 'content',
|
||||
}
|
||||
]]
|
||||
blag.generate_feed(articles, outdir, ' ', ' ', ' ', ' ')
|
||||
|
||||
with open(f'{outdir}/atom.xml') as fh:
|
||||
feed = fh.read()
|
||||
|
||||
assert '<title>title</title>' in feed
|
||||
assert '<summary type="html">description' in feed
|
||||
assert '<published>2019-06-06' in feed
|
||||
assert '<content type="html">content' in feed
|
||||
|
||||
|
||||
def test_parse_args_build():
|
||||
# test default args
|
||||
args = blag.parse_args(['build'])
|
||||
|
||||
Reference in New Issue
Block a user