Feature request: customizable post template #5

Closed
opened 2023-11-15 13:31:50 +00:00 by MrClon · 6 comments
MrClon commented 2023-11-15 13:31:50 +00:00 (Migrated from codeberg.org)

Would be cool to let user change status template. For example something like

status += status_template_from_config_file.format( **item )

instead of

status += f"{item.title}\n\n{item.link}"

In publish.py line 54

Would be cool to let user change status template. For example something like ``` status += status_template_from_config_file.format( **item ) ``` instead of ``` status += f"{item.title}\n\n{item.link}" ``` In `publish.py` line 54
marvin8 commented 2023-11-16 20:57:52 +00:00 (Migrated from codeberg.org)

Good idea... I'll have a think about how to best to this. If you have any more thoughts on templating, I'd be very happy to hear them.

Good idea... I'll have a think about how to best to this. If you have any more thoughts on templating, I'd be very happy to hear them.
MrClon commented 2023-11-16 21:50:16 +00:00 (Migrated from codeberg.org)

Here my (shitty) implementation https://codeberg.org/MrClon/feed2fedi/commits/branch/status_template_in_config.
Bad news: item.content is list of dict, and not str (at least for Atom feeds), so it can't be directly used by such "template engine". My plan is add to item content in html, plaintext and markdown formats, so user can choose what use in posts. Now code work for Atom feeds, not perfectly, but work.
Problem is items structure different for Atom and RSS feeds, so i need convert all relevant data from RSS and Atom to some format that can be used by template.
Also client should somehow signal to server what format (markdown/plaintext/html) used in post. I have no idea how to do it. Now i just set default input type for profile

Here my (shitty) implementation https://codeberg.org/MrClon/feed2fedi/commits/branch/status_template_in_config. Bad news: `item.content` is `list` of `dict`, and not `str` (at least for Atom feeds), so it can't be directly used by such "template engine". My plan is add to `item` content in html, plaintext and markdown formats, so user can choose what use in posts. Now code work for Atom feeds, not perfectly, but work. Problem is `item`s structure different for Atom and RSS feeds, so i need convert all relevant data from RSS and Atom to some format that can be used by template. Also client should somehow signal to server what format (markdown/plaintext/html) used in post. I have no idea how to do it. Now i just set default input type for profile
MrClon commented 2023-11-17 13:31:58 +00:00 (Migrated from codeberg.org)

Did md/plaintext content for template, work for Atom and RSS, available in my repo. Code in collect.py is a mess, sorry. Also it add one dependence, markdownify, but i believe it worth it

Current "template engine" (str.format) is very basic. I see two way to make templates more powerful:

  1. Use f-string by something like eval(f"f'{template}'"). Looks like bad idea
  2. Use proper template engine like jinja2

Personally i ok with str.format for now, i can get all flexibility i need by patching code, but users may want good templates. For example to cut to long content, or format datetime values

Did md/plaintext content for template, work for Atom and RSS, available in my repo. Code in `collect.py` is a mess, sorry. Also it add one dependence, `markdownify`, but i believe it worth it Current "template engine" (`str.format`) is very basic. I see two way to make templates more powerful: 1) Use f-string by something like `eval(f"f'{template}'")`. Looks like bad idea 2) Use proper template engine like `jinja2` Personally i ok with `str.format` for now, i can get all flexibility i need by patching code, but users may want good templates. For example to cut to long content, or format datetime values
marvin8 commented 2023-11-18 06:08:06 +00:00 (Migrated from codeberg.org)

Wow... looks like you are making great progress already. Unfortunately it will be a little while before I am able to implement this.

If you feel like it, I'd be happy with a PR to the wip branch.

Wow... looks like you are making great progress already. Unfortunately it will be a little while before I am able to implement this. If you feel like it, I'd be happy with a PR to the `wip` branch.
marvin8 commented 2023-11-20 20:32:44 +00:00 (Migrated from codeberg.org)

Thanks for the PR it will be included in the next release.

Still need to updated documentation before I release this and I'd like to address your other issue as well. For that I'm making a change to minimal_activitypub first.

Thanks for the PR it will be included in the next release. Still need to updated documentation before I release this and I'd like to address your other issue as well. For that I'm making a change to `minimal_activitypub` first.
marvin8 commented 2023-12-07 03:52:40 +00:00 (Migrated from codeberg.org)

Implemented in release 1.0.0

Implemented in release 1.0.0
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
marvin8/feed2fedi#5
No description provided.