aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2024-03-18 04:36:43 +0100
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2024-03-18 04:43:30 +0100
commit1ee677586ebe929d88c7ba5575b58053c928fdde (patch)
tree291d413a1539a20225f01a8039e836963b6810f0
parent0da7f975f430f89c2e6993b244d8d95b009aefa7 (diff)
downloadhaunt-blog-1ee677586ebe929d88c7ba5575b58053c928fdde.tar.gz
haunt-blog-1ee677586ebe929d88c7ba5575b58053c928fdde.tar.bz2
haunt-blog-1ee677586ebe929d88c7ba5575b58053c928fdde.zip
convert.py: add output-file argument.
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r--Makefile1
-rwxr-xr-xconvert.py17
2 files changed, 11 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index f13298c..88cecc9 100644
--- a/Makefile
+++ b/Makefile
@@ -97,7 +97,6 @@ markdown: html
sed 's#https://blog.replicant.us/##' | \
sed 's#/$$##'| \
sed 's#/#_#g'`.html \
- > \
markdown/`echo "$${url}" | \
sed 's#https://blog.replicant.us/##' | \
sed 's#/$$##'| \
diff --git a/convert.py b/convert.py
index 6c72bab..03c6965 100755
--- a/convert.py
+++ b/convert.py
@@ -25,7 +25,7 @@ import sh
import sys
def usage(progname):
- print("Usage:\n\t{} <path/to/file.html>".format(progname))
+ print("Usage:\n\t{} <input-file> <output-file>".format(progname))
# A "[1]" in the html becomes "[[1]][6]" in text.
# As we already uses references at the end a [6] would
@@ -238,16 +238,21 @@ def get_metadata(html_file_path):
return metadata
def main():
- if len(sys.argv) != 2:
+ if len(sys.argv) != 3:
usage(sys.argv[0])
sys.exit(os.EX_USAGE)
- html_file_path = sys.argv[1]
+ input_html_file_path = sys.argv[1]
+ output_markdown_file_path = sys.argv[2]
- text = get_metadata(html_file_path)
- text += convert(html_file_path)
+ text = get_metadata(input_html_file_path)
+ text += convert(input_html_file_path)
- sys.stdout.write(text)
+ if output_markdown_file_path == '-':
+ sys.stdout.write(text)
+ else:
+ with open(output_markdown_file_path, 'w') as markdown_file:
+ markdown_file.write(text)
if __name__ == '__main__':
main()