aboutsummaryrefslogtreecommitdiff
path: root/pyblog
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-05-26 16:38:13 +0200
committerneodarz <neodarz@neodarz.net>2019-05-26 16:38:13 +0200
commitf3600fccc4a02324b5cc86549e644720097c61df (patch)
tree12820ec499a6b66c52f918e9dfb14e163462ba66 /pyblog
parent0e1fd56310060d269d798aadb80784651abcba0e (diff)
downloadmy_new_personal_website-f3600fccc4a02324b5cc86549e644720097c61df.tar.xz
my_new_personal_website-f3600fccc4a02324b5cc86549e644720097c61df.zip
Move new_post to external file
Diffstat (limited to '')
-rwxr-xr-xpyblog41
1 files changed, 1 insertions, 40 deletions
diff --git a/pyblog b/pyblog
index cf8a3bf1..08e0a1a1 100755
--- a/pyblog
+++ b/pyblog
@@ -53,48 +53,9 @@ from generators import generators
from cli import cli
-def new_post(title):
- """Create a new post with metadata pre-filled.
-
- The path to the new post is printed to stdout.
-
- Returns
- -------
- 0
- On success.
-
- """
- date = utils.current_datetime()
- filename_date = date.strftime("%Y-%m-%d")
- iso_date = date.isoformat()
- display_date = "%s %d, %d" % (date.strftime("%B"), date.day, date.year)
- title_sanitized = utils.sanitize(title)
- filename = "%s-%s.md" % (filename_date, title_sanitized)
- fullpath = os.path.join(POSTSDIR, filename)
- if not os.path.isdir(POSTSDIR):
- if os.path.exists(POSTSDIR):
- os.remove(POSTSDIR)
- os.mkdir(POSTSDIR, mode=0o755)
- if os.path.exists(fullpath):
- sys.stderr.write("%serror: '%s' already exists, please pick a different title%s\n" %
- (RED, fullpath, RESET))
- return 1
- with open(fullpath, 'w', encoding='utf-8') as newpost:
- newpost.write("---\n")
- newpost.write('title: "%s"\n' % title)
- newpost.write("date: %s\n" % iso_date)
- newpost.write("date_display: %s\n" % display_date)
- newpost.write("---\n\n")
- sys.stderr.write("New post created in:\n")
- print(fullpath)
- cli.edit_post_with_editor(fullpath)
-
- return 0
-
-
def new_post_cli(args):
"""CLI wrapper around new_post."""
- new_post(args.title)
+ cli.new_post(args.title)
def touch(filename):