Skip to content

Commit

Permalink
Support hashtags, if given in frontend post metadata.
Browse files Browse the repository at this point in the history
See Issue #7
  • Loading branch information
MinchinWeb committed Jul 13, 2023
1 parent 2a98ece commit a20a62a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -5,6 +5,7 @@ Changelog
.. this is in "release" (for Sphinx) format
- :feature:`7` Support hashtags, if given in frontend post metadata.
- :release:`1.0.0 <2023-07-11>`
- :support:`-` `seafoam <https://blog.minchin.ca/label/seafoam/>`_ v2.9.0 is
being release co-currently with this, and has support for microblog posts.
Expand Down
17 changes: 17 additions & 0 deletions README.rst
Expand Up @@ -69,6 +69,23 @@ Or a post with an image:
The image path is relative to your ``content`` folder. A URL of the photo is
added to the end of the post as well.

Or with tags (or hashtags):

.. code-block:: md
<!-- ./content/micro/202307131456.md -->
date: 2023-07-13 14:56 -0600
tags: Python, Pelican, Microblogging
I'm now Microblogging with Pelican!
This will add links at the end of your post to the tags to the tag page for
your (Pelican) site.

For now, it does not pull tags out of the body of your post.

Background Notes (on Micro Blogging)
------------------------------------

Expand Down
14 changes: 13 additions & 1 deletion minchin/pelican/readers/microblog/generator.py
Expand Up @@ -71,6 +71,18 @@ def addMicroArticle(articleGenerator):

content = content.removesuffix("</p>") + " " + image_link + "</p>"

if "tags" in metadata.keys():
# new_article_metadata["tags"] = myBaseReader.process_metadata("tags", metadata["tags"])
new_article_metadata["tags"] = metadata["tags"]

# metadata["tags"] is already a list of `pelican.urlwrappers.Tag`
for tag in metadata["tags"]:
tag_url = settings["SITEURL"] + "/" + tag.url

tag_link = f'<a href="{tag_url}">#{tag.name}</a>'

content = content.removesuffix("</p>") + " " + tag_link + "</p>"

# warn if too long
safe_content = Markup(content).striptags()
post_len = len(safe_content)
Expand All @@ -87,7 +99,7 @@ def addMicroArticle(articleGenerator):
)
new_article_metadata["char_len"] = post_len

print(post_len)
# print(post_len)

new_article = Article(
content,
Expand Down
4 changes: 4 additions & 0 deletions test/content/micro/202307131456.md
@@ -0,0 +1,4 @@
date: 2023-07-13 14:56 -0600
tags: Python, Pelican, Microblogging

I'm now Microblogging with Pelican!

0 comments on commit a20a62a

Please sign in to comment.