aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README19
-rwxr-xr-xhaunthtml2wordpress.py75
-rw-r--r--website/builders/replicant-blog.scm2
3 files changed, 95 insertions, 1 deletions
diff --git a/README b/README
index 4c54ecb..70e0a91 100644
--- a/README
+++ b/README
@@ -21,6 +21,25 @@ them in markdown/).
At this stage the website is then ready to used with haunt. You can
then build it with 'make build' or 'make serve'.
+
+Reimporting articles in WordPress
+=================================
+
+If for some reasons you then need to import back some of the markdown
+articles in WordPress, you can generate the HTML pages with 'make
+markdown' like explained above, and then use haunthtml2wordpress.py on
+the generated page. It will print out the article title and the HTML
+code that you will need to copy-paste into WordPress.
+
+By default, when creating an article in WordPress, you are presented
+with a visual editor that is intended for people to create articles
+without needing to write any HTML code.
+
+Since here we need to paste HTML code here you will need to switch to
+the "code editor" to be able to do that. The [WordPress official
+documentation](https://wordpress.com/support/editors/) has more
+details on where to find that "code editor".
+
License
=======
This project is free software: you can redistribute it and/or modify
diff --git a/haunthtml2wordpress.py b/haunthtml2wordpress.py
new file mode 100755
index 0000000..883cbea
--- /dev/null
+++ b/haunthtml2wordpress.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python3
+# encoding: utf-8
+# Copyright (C) 2020, 2024 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+import bs4
+import enum
+import os
+import re
+import sys
+
+def usage(progname):
+ print("{} path/to/file.html".format(progname))
+ sys.exit(1)
+
+def fixup_html(html):
+ open_p = 0
+ buf = [None] * 4
+ for c in html:
+ buf[0] = buf[1]
+ buf[1] = buf[2]
+ buf[2] = buf[3]
+ buf[3] = c
+
+ if buf[1] == '<' and buf[2] == 'p' and buf[3] == '>':
+ open_p += 1
+ if buf[0] == '<' and buf[1] == '/' and buf[2] == 'p' and buf[3] == '>':
+ open_p -= 1
+
+ if c == '\n' and open_p > 0:
+ print(' ', end='')
+ else:
+ print(c, end='')
+def main():
+ if len(sys.argv) != 2:
+ usage(sys.argv[0])
+
+ html_file_path = sys.argv[1]
+
+ with open(html_file_path) as html_file:
+ soup = bs4.BeautifulSoup(html_file, 'html.parser')
+
+ #################
+ # Article title #
+ #################
+ article_title = soup.find(id='title').text
+ print("Title: {}".format(article_title))
+
+ ################
+ # Post content #
+ ################
+ post_content = soup.find(id='post-content').extract()
+ pretty_html = post_content.prettify()
+ # Remove the outer <div id="post-content"> and </div>
+ div_content = os.linesep.join(pretty_html.split(os.linesep)[1:-1]) + os.linesep
+ print("Post content:")
+ print('-' * 38 + ' %< ' + '-' * 38)
+ fixup_html(div_content)
+ print('-' * 38 + ' >% ' + '-' * 38)
+
+if __name__ == '__main__':
+ main()
+
diff --git a/website/builders/replicant-blog.scm b/website/builders/replicant-blog.scm
index cab758c..be15bcd 100644
--- a/website/builders/replicant-blog.scm
+++ b/website/builders/replicant-blog.scm
@@ -68,7 +68,7 @@
(define (replicant-default-post-template post)
`((h1 (@ (id "title")) ,(post-ref post 'title))
- (div ,(post-sxml post))))
+ (div (@ (id "post-content")) ,(post-sxml post))))
(define (replicant-default-collection-template site title posts prefix)
(define (post-uri post)