forked from github.com/blag
Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
713b53d0d9 | ||
|
|
2d1d0ab302 | ||
|
|
572710fab1 | ||
|
|
0b66c5fbf4 | ||
|
|
18ecd82c5a | ||
|
|
a74f36be8a | ||
|
|
dd7d6cdae2 | ||
|
|
39e6aa2676 | ||
|
|
93f6840168 | ||
|
|
e27d82ac2a | ||
|
|
88b4fc8233 | ||
|
|
8923b0bb6e | ||
|
|
2671239ac1 | ||
|
|
7aa6cebb63 | ||
|
|
4869ea0fd2 | ||
|
|
aeedd9b73a | ||
|
|
52412b8926 | ||
|
|
c0dae31b60 | ||
|
|
2366ee2def | ||
|
|
67f24642e5 | ||
|
|
f1020637e6 | ||
|
|
a4d596b79d | ||
|
|
79edd04ee8 | ||
|
|
9cdecdccf7 | ||
|
|
499b0dfe11 | ||
|
|
72971408b2 | ||
|
|
6445f31204 | ||
|
|
98b97fbbbd | ||
|
|
df65dee488 | ||
|
|
d227392c79 |
6
.github/dependabot.yml
vendored
Normal file
6
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "pip"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
1
.github/workflows/python-package.yaml
vendored
1
.github/workflows/python-package.yaml
vendored
@@ -19,6 +19,7 @@ jobs:
|
||||
python-version:
|
||||
- 3.8
|
||||
- 3.9
|
||||
- "3.10"
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
22
CHANGELOG.md
22
CHANGELOG.md
@@ -1,6 +1,24 @@
|
||||
# Changelog
|
||||
|
||||
## [0.0.0] - YYYY-MM-DD
|
||||
## [1.1.0] - 2021-1006
|
||||
|
||||
*
|
||||
* added Python 3.10 to list of supported versions to test against
|
||||
* added dependabot to github workflows
|
||||
* updated various dependencies:
|
||||
* pygments 2.10.0
|
||||
* sphinx 4.2.0
|
||||
* twine 3.4.2
|
||||
* wheel 0.37.0
|
||||
* pytest 6.2.5
|
||||
|
||||
## [1.0.0] - 2021-08-18
|
||||
|
||||
* first 1.0 release!
|
||||
* bump requirements of feedgenerator to 1.9.2. this version uses the
|
||||
description to provide a subtitle for the feed
|
||||
|
||||
## [0.0.9] - 2021-06-22
|
||||
|
||||
* updated to jinja 3.0
|
||||
* updated to sphinx 4.0
|
||||
* added link to changelog
|
||||
|
||||
@@ -289,7 +289,7 @@ def process_markdown(convertibles, input_dir, output_dir,
|
||||
articles.append((dst, context))
|
||||
result = article_template.render(context)
|
||||
else:
|
||||
pages.append((dst, content))
|
||||
pages.append((dst, context))
|
||||
result = page_template.render(context)
|
||||
with open(f'{output_dir}/{dst}', 'w') as fh_dest:
|
||||
fh_dest.write(result)
|
||||
@@ -392,7 +392,7 @@ def generate_tags(articles, tags_template, tag_template, output_dir):
|
||||
# get tags number of occurrences
|
||||
all_tags = {}
|
||||
for _, context in articles:
|
||||
tags = context.get('tags', None)
|
||||
tags = context.get('tags', [])
|
||||
for tag in tags:
|
||||
all_tags[tag] = all_tags.get(tag, 0) + 1
|
||||
# sort by occurrence
|
||||
@@ -405,7 +405,7 @@ def generate_tags(articles, tags_template, tag_template, output_dir):
|
||||
# get tags and archive per tag
|
||||
all_tags = {}
|
||||
for dst, context in articles:
|
||||
tags = context.get('tags', None)
|
||||
tags = context.get('tags', [])
|
||||
for tag in tags:
|
||||
archive = all_tags.get(tag, [])
|
||||
entry = context.copy()
|
||||
|
||||
@@ -30,7 +30,7 @@ def markdown_factory():
|
||||
"""
|
||||
md = Markdown(
|
||||
extensions=[
|
||||
'meta', 'fenced_code', 'codehilite',
|
||||
'meta', 'fenced_code', 'codehilite', 'smarty',
|
||||
MarkdownLinkExtension()
|
||||
],
|
||||
output_format='html5',
|
||||
|
||||
@@ -1 +1 @@
|
||||
__VERSION__ = '0.0.6'
|
||||
__VERSION__ = '1.1.0'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
sphinx==3.5.3
|
||||
twine==3.4.1
|
||||
wheel==0.36.2
|
||||
pytest==6.2.2
|
||||
pytest-cov==2.11.1
|
||||
flake8==3.9.0
|
||||
sphinx==4.2.0
|
||||
twine==3.4.2
|
||||
wheel==0.37.0
|
||||
pytest==6.2.5
|
||||
pytest-cov==2.12.1
|
||||
flake8==3.9.2
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
markdown==3.3.4
|
||||
feedgenerator==1.9.1
|
||||
jinja2==2.11.3
|
||||
pygments==2.8.1
|
||||
feedgenerator==1.9.2
|
||||
jinja2==3.0.1
|
||||
pygments==2.10.0
|
||||
|
||||
3
setup.py
3
setup.py
@@ -1,6 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
|
||||
from setuptools import setup
|
||||
|
||||
meta = {}
|
||||
@@ -20,6 +19,8 @@ setup(
|
||||
project_urls={
|
||||
'Documentation': 'https://blag.readthedocs.io/',
|
||||
'Source': 'https://github.com/venthur/blag',
|
||||
'Changelog':
|
||||
'https://github.com/venthur/blag/blob/master/CHANGELOG.md',
|
||||
},
|
||||
python_requires='>=3.8',
|
||||
package_data={
|
||||
|
||||
86
tests/conftest.py
Normal file
86
tests/conftest.py
Normal file
@@ -0,0 +1,86 @@
|
||||
from tempfile import TemporaryDirectory
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
from blag import blag
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def environment():
|
||||
site = {
|
||||
'base_url': 'site base_url',
|
||||
'title': 'site title',
|
||||
'description': 'site description',
|
||||
'author': 'site author',
|
||||
}
|
||||
env = blag.environment_factory(globals_=dict(site=site))
|
||||
yield env
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def page_template(environment):
|
||||
yield environment.get_template('page.html')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def article_template(environment):
|
||||
yield environment.get_template('article.html')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def archive_template(environment):
|
||||
yield environment.get_template('archive.html')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tags_template(environment):
|
||||
yield environment.get_template('tags.html')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tag_template(environment):
|
||||
yield environment.get_template('tag.html')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cleandir():
|
||||
"""Create a temporary workind directory and cwd.
|
||||
|
||||
"""
|
||||
config = """
|
||||
[main]
|
||||
base_url = https://example.com/
|
||||
title = title
|
||||
description = description
|
||||
author = a. u. thor
|
||||
"""
|
||||
|
||||
with TemporaryDirectory() as dir:
|
||||
for d in 'content', 'build', 'static', 'templates':
|
||||
os.mkdir(f'{dir}/{d}')
|
||||
with open(f'{dir}/config.ini', 'w') as fh:
|
||||
fh.write(config)
|
||||
# change directory
|
||||
old_cwd = os.getcwd()
|
||||
os.chdir(dir)
|
||||
yield dir
|
||||
# and change back afterwards
|
||||
os.chdir(old_cwd)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def args(cleandir):
|
||||
|
||||
class NameSpace:
|
||||
def __init__(self, **kwargs):
|
||||
for name in kwargs:
|
||||
setattr(self, name, kwargs[name])
|
||||
|
||||
args = NameSpace(
|
||||
input_dir='content',
|
||||
output_dir='build',
|
||||
static_dir='static',
|
||||
template_dir='templates',
|
||||
)
|
||||
yield args
|
||||
@@ -7,19 +7,13 @@ import pytest
|
||||
from blag import blag
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def outdir():
|
||||
with TemporaryDirectory() as dir:
|
||||
yield dir
|
||||
|
||||
|
||||
def test_generate_feed(outdir):
|
||||
def test_generate_feed(cleandir):
|
||||
articles = []
|
||||
blag.generate_feed(articles, outdir, ' ', ' ', ' ', ' ')
|
||||
assert os.path.exists(f'{outdir}/atom.xml')
|
||||
blag.generate_feed(articles, 'build', ' ', ' ', ' ', ' ')
|
||||
assert os.path.exists('build/atom.xml')
|
||||
|
||||
|
||||
def test_feed(outdir):
|
||||
def test_feed(cleandir):
|
||||
articles = [
|
||||
[
|
||||
'dest1.html',
|
||||
@@ -40,9 +34,9 @@ def test_feed(outdir):
|
||||
|
||||
]
|
||||
|
||||
blag.generate_feed(articles, outdir, 'https://example.com/', 'blog title',
|
||||
'blog description', 'blog author')
|
||||
with open(f'{outdir}/atom.xml') as fh:
|
||||
blag.generate_feed(articles, 'build', 'https://example.com/',
|
||||
'blog title', 'blog description', 'blog author')
|
||||
with open('build/atom.xml') as fh:
|
||||
feed = fh.read()
|
||||
|
||||
assert '<title>blog title</title>' in feed
|
||||
@@ -66,7 +60,7 @@ def test_feed(outdir):
|
||||
assert '<link href="https://example.com/dest2.html"' in feed
|
||||
|
||||
|
||||
def test_generate_feed_with_description(outdir):
|
||||
def test_generate_feed_with_description(cleandir):
|
||||
# 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 = [[
|
||||
@@ -78,9 +72,9 @@ def test_generate_feed_with_description(outdir):
|
||||
'content': 'content',
|
||||
}
|
||||
]]
|
||||
blag.generate_feed(articles, outdir, ' ', ' ', ' ', ' ')
|
||||
blag.generate_feed(articles, 'build', ' ', ' ', ' ', ' ')
|
||||
|
||||
with open(f'{outdir}/atom.xml') as fh:
|
||||
with open('build/atom.xml') as fh:
|
||||
feed = fh.read()
|
||||
|
||||
assert '<title>title</title>' in feed
|
||||
@@ -180,3 +174,106 @@ def test_environment_factory():
|
||||
env = blag.environment_factory(globals_=globals_)
|
||||
assert env.globals['foo'] == 'bar'
|
||||
assert env.globals['test'] == 'me'
|
||||
|
||||
|
||||
def test_process_markdown(cleandir, page_template, article_template):
|
||||
page1 = """\
|
||||
title: some page
|
||||
|
||||
some text
|
||||
foo bar
|
||||
"""
|
||||
|
||||
article1 = """\
|
||||
title: some article1
|
||||
date: 2020-01-01
|
||||
|
||||
some text
|
||||
foo bar
|
||||
"""
|
||||
|
||||
article2 = """\
|
||||
title: some article2
|
||||
date: 2021-01-01
|
||||
|
||||
some text
|
||||
foo bar
|
||||
"""
|
||||
|
||||
convertibles = []
|
||||
for i, txt in enumerate((page1, article1, article2)):
|
||||
i = str(i)
|
||||
with open(f'content/{i}', 'w') as fh:
|
||||
fh.write(txt)
|
||||
convertibles.append([i, i])
|
||||
|
||||
articles, pages = blag.process_markdown(
|
||||
convertibles,
|
||||
'content',
|
||||
'build',
|
||||
page_template,
|
||||
article_template
|
||||
)
|
||||
|
||||
assert isinstance(articles, list)
|
||||
assert len(articles) == 2
|
||||
for dst, context in articles:
|
||||
assert isinstance(dst, str)
|
||||
assert isinstance(context, dict)
|
||||
assert 'content' in context
|
||||
|
||||
assert isinstance(pages, list)
|
||||
assert len(pages) == 1
|
||||
for dst, context in pages:
|
||||
assert isinstance(dst, str)
|
||||
assert isinstance(context, dict)
|
||||
assert 'content' in context
|
||||
|
||||
|
||||
def test_build(args):
|
||||
page1 = """\
|
||||
title: some page
|
||||
|
||||
some text
|
||||
foo bar
|
||||
"""
|
||||
|
||||
article1 = """\
|
||||
title: some article1
|
||||
date: 2020-01-01
|
||||
tags: foo, bar
|
||||
|
||||
some text
|
||||
foo bar
|
||||
"""
|
||||
|
||||
article2 = """\
|
||||
title: some article2
|
||||
date: 2021-01-01
|
||||
tags: baz
|
||||
|
||||
some text
|
||||
foo bar
|
||||
"""
|
||||
|
||||
# write some convertibles
|
||||
convertibles = []
|
||||
for i, txt in enumerate((page1, article1, article2)):
|
||||
i = str(i)
|
||||
with open(f'{args.input_dir}/{i}.md', 'w') as fh:
|
||||
fh.write(txt)
|
||||
convertibles.append([i, i])
|
||||
|
||||
# some static files
|
||||
with open(f'{args.static_dir}/test', 'w') as fh:
|
||||
fh.write('hello')
|
||||
|
||||
os.mkdir(f'{args.input_dir}/testdir')
|
||||
with open(f'{args.input_dir}/testdir/test', 'w') as fh:
|
||||
fh.write('hello')
|
||||
|
||||
blag.build(args)
|
||||
|
||||
|
||||
def test_main(cleandir):
|
||||
blag.main(['build'])
|
||||
|
||||
@@ -1,30 +1,21 @@
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
from tempfile import TemporaryDirectory
|
||||
from blag import devserver
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tempdir():
|
||||
with TemporaryDirectory() as dir:
|
||||
yield dir
|
||||
|
||||
|
||||
def test_get_last_modified(tempdir):
|
||||
def test_get_last_modified(cleandir):
|
||||
# take initial time
|
||||
t1 = devserver.get_last_modified([tempdir])
|
||||
t1 = devserver.get_last_modified(['content'])
|
||||
|
||||
# wait a bit, create a file and measure again
|
||||
time.sleep(0.1)
|
||||
with open(f'{tempdir}/test', 'w') as fh:
|
||||
with open('content/test', 'w') as fh:
|
||||
fh.write('boo')
|
||||
t2 = devserver.get_last_modified([tempdir])
|
||||
t2 = devserver.get_last_modified(['content'])
|
||||
|
||||
# wait a bit and take time again
|
||||
time.sleep(0.1)
|
||||
t3 = devserver.get_last_modified([tempdir])
|
||||
t3 = devserver.get_last_modified(['content'])
|
||||
|
||||
assert t2 > t1
|
||||
assert t2 == t3
|
||||
|
||||
@@ -49,3 +49,31 @@ def test_convert_metadata(input_, expected):
|
||||
def test_markdown_factory():
|
||||
md = markdown_factory()
|
||||
assert isinstance(md, markdown.Markdown)
|
||||
|
||||
|
||||
def test_smarty():
|
||||
md = markdown_factory()
|
||||
|
||||
md1 = """
|
||||
|
||||
this --- is -- a test ...
|
||||
|
||||
"""
|
||||
html, meta = convert_markdown(md, md1)
|
||||
assert 'mdash' in html
|
||||
assert 'ndash' in html
|
||||
assert 'hellip' in html
|
||||
|
||||
|
||||
def test_smarty_code():
|
||||
md = markdown_factory()
|
||||
|
||||
md1 = """
|
||||
```
|
||||
this --- is -- a test ...
|
||||
```
|
||||
"""
|
||||
html, meta = convert_markdown(md, md1)
|
||||
assert 'mdash' not in html
|
||||
assert 'ndash' not in html
|
||||
assert 'hellip' not in html
|
||||
|
||||
@@ -1,46 +1,5 @@
|
||||
import datetime
|
||||
|
||||
import pytest
|
||||
|
||||
from blag import blag
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def environment():
|
||||
site = {
|
||||
'base_url': 'site base_url',
|
||||
'title': 'site title',
|
||||
'description': 'site description',
|
||||
'author': 'site author',
|
||||
}
|
||||
env = blag.environment_factory(globals_=dict(site=site))
|
||||
yield env
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def page_template(environment):
|
||||
yield environment.get_template('page.html')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def article_template(environment):
|
||||
yield environment.get_template('article.html')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def archive_template(environment):
|
||||
yield environment.get_template('archive.html')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tags_template(environment):
|
||||
yield environment.get_template('tags.html')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tag_template(environment):
|
||||
yield environment.get_template('tag.html')
|
||||
|
||||
|
||||
def test_page(page_template):
|
||||
ctx = {
|
||||
|
||||
Reference in New Issue
Block a user