mirror of
https://git.ari.lt/ari.lt/ari.lt.git
synced 2025-02-04 17:49:24 +01:00
67 lines
1.7 KiB
Python
Executable file
67 lines
1.7 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import asyncio
|
|
import os
|
|
import markdown
|
|
|
|
|
|
async def main() -> int:
|
|
open("/tmp/blog.md", "w").close()
|
|
|
|
blog_title = input("Blog title: ")
|
|
|
|
input(
|
|
"Now this script will open your editor, enter the markdown you want in your blog there. press enter to continue"
|
|
)
|
|
|
|
if os.getenv("EDITOR"):
|
|
os.system(f"{os.getenv('EDITOR')} /tmp/blog.md")
|
|
else:
|
|
os.system(f"{input('What editor should I use?: ')} /tmp/blog.md")
|
|
|
|
with open("/tmp/blog.md", "r") as f:
|
|
blog_content = f.read()
|
|
|
|
content = """# %s
|
|
<hr/>
|
|
%s""" % (
|
|
blog_title,
|
|
blog_content,
|
|
)
|
|
|
|
with open(
|
|
f"./page/blog/blogs/{blog_title.replace(' ', '-').replace('/', '_')}.html", "w"
|
|
) as f:
|
|
f.write(markdown.markdown(content))
|
|
|
|
with open("./page/blog/index.md", "a") as f:
|
|
f.write(
|
|
f"\n* [{blog_title}](/page/blog/blogs/{blog_title.replace(' ', '-').replace('/', '_')}.html)"
|
|
)
|
|
|
|
with open("./page/blog/index.html", "w") as f:
|
|
with open("./page/blog/index.md", "r") as md:
|
|
f.write(
|
|
"""<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Ari::web -> blog</title>
|
|
</head>
|
|
<body>
|
|
<h1>My blogs</h1>
|
|
<div>
|
|
%s
|
|
<div>
|
|
</body>
|
|
</html>
|
|
<!-- this is automatically generated by scripts/add_blog -->""" % markdown.markdown(md.read()))
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
assert main.__annotations__.get("return") is int, "main() should return an integer"
|
|
exit(asyncio.run(main()))
|