Skip to content

Commit

Permalink
Merge pull request #6 from ryancheley/v0.3.0
Browse files Browse the repository at this point in the history
V0.3.0
  • Loading branch information
ryancheley authored Jan 16, 2022
2 parents 59519f1 + 8a022d5 commit 2a1debf
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 18 deletions.
44 changes: 30 additions & 14 deletions pelican/plugins/pelican_to_sqlite/pelican_to_sqlite.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import html2text
import sqlite_utils

from pelican import signals
Expand All @@ -7,27 +8,42 @@
db = sqlite_utils.Database(DATABASE)


def save_items(record: dict, table: str, db: sqlite_utils.Database) -> None:
def save_items(record: dict, table: str, db: sqlite_utils.Database) -> None: # pragma: no cover
db[table].insert(record, pk="slug", alter=True, replace=True)


# Hook function, with the right parameters
def run(_, content):
if content.status == "published":
def create_record(content) -> dict:
record = {}
author = content.author.name
category = content.category.name
post_content = html2text.html2text(content.content)
published_date = content.date.strftime("%Y-%m-%d")
slug = content.slug
summary = html2text.html2text(content.summary)
title = content.title
url = "https://www.ryancheley.com/" + content.url
status = content.status
if status == "published":
record = {
"author": content.author.name,
"category": content.category.name,
"content": content.content,
"published_date": content.date.strftime("%Y-%m-%d"),
"slug": content.slug,
"summary": content.summary,
"title": content.title,
"url": "https://www.ryancheley.com/" + content.url,
"author": author,
"category": category,
"content": post_content,
"published_date": published_date,
"slug": slug,
"summary": summary,
"title": title,
"url": url,
}
save_items(record, "content", db)
return record


# Hook function, with the right parameters
def run(_, content): # pragma: no cover
record = create_record(content)
save_items(record, "content", db)


# Module entry point
def register():
def register(): # pragma: no cover
# Connect the run hook function to the content_written signal
signals.article_generator_write_article.connect(run)
31 changes: 31 additions & 0 deletions pelican/plugins/pelican_to_sqlite/test_pelican_to_sqlite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from pelican.contents import Article
from pelican.urlwrappers import Author, Category
from pelican.utils import SafeDatetime

from .pelican_to_sqlite import create_record


def test_create_record():
metadata = {
"author": Author("ryan", settings=None),
"category": Category("musings", settings=None),
"date": SafeDatetime.fromisoformat("2016-10-03"),
"slug": "vins-last-game",
"summary": "<p>This is the summary</p>",
"title": "Vin's Last Game",
"url": "2016/10/03/vins-last-game/",
}
content = Article(content="<p>This is the content</p>", metadata=metadata)

actual = create_record(content)
expected = {
"author": "ryan",
"category": "musings",
"content": "This is the content\n\n",
"published_date": "2016-10-03",
"slug": "vins-last-game",
"summary": "This is the summary\n\n",
"title": "Vin's Last Game",
"url": "https://www.ryancheley.com/2016/10/03/vins-last-game/",
}
assert actual == expected
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from setuptools import find_packages, setup

VERSION = "0.2.0"
VERSION = "0.3.0"


def get_long_description():
Expand All @@ -23,7 +23,7 @@ def get_long_description():
version=VERSION,
license="Apache License, Version 2.0",
packages=find_packages(),
install_requires=["sqlite-utils", "click"],
install_requires=["sqlite-utils", "click", "html2text", "pelican"],
extras_require={"test": ["pytest"]},
tests_require=["pelican-to-sqlite[test]"],
setup_requires=["pytest-runner"],
Expand Down
2 changes: 0 additions & 2 deletions tests/test_pelican_to_sqlite.py

This file was deleted.

0 comments on commit 2a1debf

Please sign in to comment.