-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c181c42
commit 4bc2ea1
Showing
9 changed files
with
88 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,27 @@ | ||
from .collection import Collection | ||
from .feeds import RSSFeed | ||
from .page import Page | ||
from .parsers.markdown import MarkdownPageParser | ||
|
||
|
||
class BlogPost(Page): | ||
"""Page Like object with slight modifications to work with BlogPosts.""" | ||
invalid_attrs = ["slug"] | ||
|
||
|
||
class Blog(Collection): | ||
""" | ||
Custom :py:class:`collection.Collection` class with archiving enabled, sort by `date` by default. | ||
Todos: | ||
TODOS: | ||
- Add Support for JSON Feeds | ||
- Rename the archive items so they are not private | ||
""" | ||
|
||
BasePageParser = MarkdownPageParser | ||
content_type: BlogPost = BlogPost | ||
sort_reverse: bool = True | ||
sort_by = "date" | ||
has_archive = True | ||
Feed = RSSFeed | ||
|
||
def latest(self, count: int = 1): | ||
"""Get the latest post from the collection.""" | ||
latest_pages = list(sorted( | ||
self.__iter__(), | ||
key=lambda x:getattr(x, self.sort_by), | ||
reverse=self.sort_reverse))[0:count] | ||
return latest_pages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import pytest | ||
from src.render_engine.hookspecs import hook_impl | ||
from src.render_engine.page import Page | ||
from src.render_engine.site import Site | ||
|
||
|
||
class FakePlugin: | ||
"""Clean the output folder before rendering""" | ||
|
||
@hook_impl | ||
def pre_build_site(site: type[Site]): | ||
"""Clean the output folder before rendering""" | ||
pass | ||
|
||
@pytest.fixture | ||
def site(): | ||
class TestSite(Site): | ||
plugins = [ | ||
FakePlugin, | ||
] | ||
|
||
return TestSite() | ||
|
||
def test_register_plugins(site): | ||
"""Check that the plugin is registered""" | ||
assert site._pm.list_name_plugin()[0][0] == 'FakePlugin' | ||
|
||
|
||
def test_page_plugin_inherits_from_page(site): | ||
|
||
class TestPage(Page): | ||
pass | ||
|
||
|
||
page = Page() | ||
page.register_plugins(*site.plugins) | ||
assert page._pm.list_name_plugin()[0][0] == 'FakePlugin' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters