From f11187221f70a6150eceed30d89c25d788e5393a Mon Sep 17 00:00:00 2001 From: Jordan Robinson Date: Wed, 24 Sep 2025 23:21:35 +0100 Subject: [PATCH] update blog import to include parsing of tags like from the export --- main/views/general.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/main/views/general.py b/main/views/general.py index b4c38f847ed40682a689ff660030fca13c03e2d3..7da38d319f2cdf4b61e133591c1ef5634081e46b 100644 --- a/main/views/general.py +++ b/main/views/general.py @@ -866,18 +866,29 @@ class BlogImport(LoginRequiredMixin, FormView): def form_valid(self, form): files = form.cleaned_data["file"] + tag_line_re = re.compile(r"^> Tags:\s*(.+)$", flags=re.MULTILINE | re.IGNORECASE) + for f in files: try: content = f.read().decode("utf-8") except (UnicodeDecodeError, ValueError): form.add_error("file", "File is not valid UTF-8.") return self.form_invalid(form) + + tags = None + match = tag_line_re.search(content) + if match: + tags = ", ".join([t.strip() for t in match.group(1).split(",")]) + # remove the tags line from the content + content = tag_line_re.sub("", content).strip() + models.Post.objects.create( title=f.name, slug=util.create_post_slug(f.name, self.request.user), body=content, owner=self.request.user, published_at=None, + tags=tags, ) return HttpResponseRedirect(self.get_success_url())