2021-10-22 07:40:32 +03:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import asyncio
|
2021-10-22 09:36:39 +03:00
|
|
|
import os, subprocess
|
2021-10-22 07:40:32 +03:00
|
|
|
import markdown
|
|
|
|
|
|
|
|
|
2021-10-22 09:36:39 +03:00
|
|
|
|
2021-10-22 07:40:32 +03:00
|
|
|
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()
|
|
|
|
|
2021-10-22 09:39:50 +03:00
|
|
|
date = subprocess.check_output(['date', '+%F %T %Z']).decode().rstrip("\n")
|
2021-10-22 09:36:39 +03:00
|
|
|
content = f"""# %s
|
2021-10-22 09:26:20 +03:00
|
|
|
|
2021-10-22 09:36:39 +03:00
|
|
|
{date} | [back](..) | [home](/) | [git](//github.com/TruncatedDinosour/website)
|
2021-10-22 09:26:20 +03:00
|
|
|
|
2021-10-22 07:40:32 +03:00
|
|
|
<hr/>
|
2021-10-22 09:26:20 +03:00
|
|
|
|
2021-10-22 07:40:32 +03:00
|
|
|
%s""" % (
|
|
|
|
blog_title,
|
|
|
|
blog_content,
|
|
|
|
)
|
|
|
|
|
|
|
|
with open(
|
|
|
|
f"./page/blog/blogs/{blog_title.replace(' ', '-').replace('/', '_')}.html", "w"
|
|
|
|
) as f:
|
2021-10-22 09:26:20 +03:00
|
|
|
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>
|
|
|
|
<div>
|
|
|
|
%s
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
<!-- this is automatically generated by scripts/add_blog -->""" % markdown.markdown(content))
|
2021-10-22 07:40:32 +03:00
|
|
|
|
|
|
|
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
|
2021-10-22 09:26:20 +03:00
|
|
|
</div>
|
2021-10-22 07:40:32 +03:00
|
|
|
</body>
|
|
|
|
</html>
|
2021-10-22 07:51:17 +03:00
|
|
|
<!-- this is automatically generated by scripts/add_blog -->"""
|
|
|
|
% markdown.markdown(md.read())
|
|
|
|
)
|
2021-10-22 07:40:32 +03:00
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
assert main.__annotations__.get("return") is int, "main() should return an integer"
|
|
|
|
exit(asyncio.run(main()))
|