add rss content to post history and generate it when creating or editing a post

This commit is contained in:
2025-12-14 07:05:52 +03:00
parent 96c37f9081
commit 0898c56a51
2 changed files with 6 additions and 1 deletions

View File

@@ -43,6 +43,7 @@ MIGRATIONS = [
add_signature_format, add_signature_format,
create_default_bookmark_collections, create_default_bookmark_collections,
add_display_name, add_display_name,
'ALTER TABLE "post_history" ADD COLUMN "content_rss" STRING DEFAULT NULL'
] ]
def run_migrations(): def run_migrations():

View File

@@ -2,7 +2,7 @@ from flask import (
Blueprint, redirect, url_for, flash, render_template, request Blueprint, redirect, url_for, flash, render_template, request
) )
from .users import login_required, get_active_user from .users import login_required, get_active_user
from ..lib.babycode import babycode_to_html, BABYCODE_VERSION from ..lib.babycode import babycode_to_html, babycode_to_rssxml, BABYCODE_VERSION
from ..constants import InfoboxKind from ..constants import InfoboxKind
from ..db import db from ..db import db
from ..models import Posts, PostHistory, Threads, Topics, Mentions from ..models import Posts, PostHistory, Threads, Topics, Mentions
@@ -12,6 +12,7 @@ bp = Blueprint("posts", __name__, url_prefix = "/post")
def create_post(thread_id, user_id, content, markup_language="babycode"): def create_post(thread_id, user_id, content, markup_language="babycode"):
parsed_content = babycode_to_html(content) parsed_content = babycode_to_html(content)
parsed_rss = babycode_to_rssxml(content)
with db.transaction(): with db.transaction():
post = Posts.create({ post = Posts.create({
"thread_id": thread_id, "thread_id": thread_id,
@@ -22,6 +23,7 @@ def create_post(thread_id, user_id, content, markup_language="babycode"):
revision = PostHistory.create({ revision = PostHistory.create({
"post_id": post.id, "post_id": post.id,
"content": parsed_content.result, "content": parsed_content.result,
"content_rss": parsed_rss,
"is_initial_revision": True, "is_initial_revision": True,
"original_markup": content, "original_markup": content,
"markup_language": markup_language, "markup_language": markup_language,
@@ -43,11 +45,13 @@ def create_post(thread_id, user_id, content, markup_language="babycode"):
def update_post(post_id, new_content, markup_language='babycode'): def update_post(post_id, new_content, markup_language='babycode'):
parsed_content = babycode_to_html(new_content) parsed_content = babycode_to_html(new_content)
parsed_rss = babycode_to_rssxml(new_content)
with db.transaction(): with db.transaction():
post = Posts.find({'id': post_id}) post = Posts.find({'id': post_id})
new_revision = PostHistory.create({ new_revision = PostHistory.create({
'post_id': post.id, 'post_id': post.id,
'content': parsed_content.result, 'content': parsed_content.result,
"content_rss": parsed_rss,
'is_initial_revision': False, 'is_initial_revision': False,
'original_markup': new_content, 'original_markup': new_content,
'markup_language': markup_language, 'markup_language': markup_language,