Skip to content

Commit a3ff732

Browse files
authored
feat: create new metadata 'fatgs' to create a #tag on a Fediverse post that is not included in the Pelican article
1 parent ba6f14f commit a3ff732

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ Hashtag(s) are taken - if any - from `article.tags` and concatenated separating
3434

3535
Pelican can nicely handle tags with whitespaces (for example `#My nice article`) but in Mastodon they must be written without. For this reason all whitespaces from Pelican hashtags will be removed before publishing (`#Mynicearticle`).
3636

37+
### New metadata **ftags**
38+
You can use the `ftags` metadata to add specific tags to a Fediverse post without including Pelican hashtags.
39+
```markdown
40+
Title: This is a ftags sample usage
41+
Date: 2025-05-23
42+
Slug: ftags-sample
43+
tags: tag_on_blog_and_fediverse, another_one
44+
ftags: TagOnlyOnFediverse, SecondOne
45+
46+
```
47+
3748
## Mastodon APIs
3849

3950
This plugin depends on [Mastodon.py](https://github.com/halcy/Mastodon.py).

fediverse.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -113,27 +113,33 @@ def post_updates(generator, writer):
113113
articlecleantext = html.fromstring(articlehtmltext)
114114
summary_to_publish = articlecleantext.text_content().strip() + '\n'
115115
read_more = mt_read_more + article.get_siteurl() + '/' + article.url + '\n\n'
116+
117+
fedi_tag_list = []
118+
tags_to_publish = ''
119+
120+
if hasattr(article, 'ftags'):
121+
for ftag in article.ftags.split(','):
122+
fedi_tag_list.append('#' + ftag.replace(' ', ''))
123+
116124
if hasattr(article, 'tags'):
117-
taglist = article.tags
118-
new_taglist = []
119-
for i in taglist:
120-
new_taglist.append('#' + str(i))
121-
tags_to_publish = ', '.join(str(x).replace(" ", "") for x in new_taglist)
122-
toot_length = len(title_to_publish) + len(summary_to_publish) + len(read_more) + len(tags_to_publish)
123-
if toot_length > toot_maxlength:
124-
truncate = toot_maxlength - len(title_to_publish) - len(tags_to_publish) - len(read_more) - 4
125-
summary_to_publish = summary_to_publish[:truncate] + ' ...' + '\n'
126-
mastodon_toot = title_to_publish + summary_to_publish + read_more + tags_to_publish
127-
else:
128-
mastodon_toot = title_to_publish + summary_to_publish + read_more + tags_to_publish
129-
else:
130-
toot_length = len(title_to_publish) + len(summary_to_publish) + len(read_more)
131-
if toot_length > toot_maxlength:
132-
truncate = toot_maxlength - len(title_to_publish) - len(read_more) - 4
133-
summary_to_publish = summary_to_publish[:truncate] + ' ...' + '\n'
134-
mastodon_toot = title_to_publish + summary_to_publish + read_more
135-
else:
136-
mastodon_toot = title_to_publish + summary_to_publish + read_more
125+
for tag in article.tags:
126+
fedi_tag_list.append('#' + str(tag).replace(' ',''))
127+
128+
if fedi_tag_list:
129+
tags_to_publish = ', '.join(fedi_tag_list)
130+
131+
toot_length = (len(title_to_publish) +
132+
len(summary_to_publish) +
133+
len(read_more) +
134+
len(tags_to_publish))
135+
136+
if toot_length > toot_maxlength:
137+
truncate = (toot_maxlength - len(title_to_publish) -
138+
len(tags_to_publish) - len(read_more) - 4)
139+
summary_to_publish = summary_to_publish[
140+
:truncate] + ' ...' + '\n'
141+
142+
mastodon_toot = title_to_publish + summary_to_publish + read_more + tags_to_publish
137143

138144
mastodon.status_post(mastodon_toot, visibility=mt_visibility)
139145

0 commit comments

Comments
 (0)