updates
This commit is contained in:
13
argparser.py
13
argparser.py
@@ -6,6 +6,13 @@ argparser = argparse.ArgumentParser(
|
|||||||
description = Config.APP_DESCRIPTION,
|
description = Config.APP_DESCRIPTION,
|
||||||
epilog = f"See {Config.APP_SRC_URL} for more info.")
|
epilog = f"See {Config.APP_SRC_URL} for more info.")
|
||||||
|
|
||||||
argparser.add_argument('--init', action='store_true', help = 'Initialize new site')
|
subparsers = argparser.add_subparsers(dest='command', required=True)
|
||||||
argparser.add_argument('--content', '--edit', type = str, help = 'Create new content')
|
|
||||||
argparser.add_argument('--build', action='store_true', help = 'Build the site')
|
#argparser.add_argument('--init', action='store_true', help = 'Initialize new site')
|
||||||
|
#argparser.add_argument('--content', '--edit', type = str, help = 'Create new content')
|
||||||
|
subparsers.add_parser('init', help = 'Initialize new site.')
|
||||||
|
subparsers.add_parser('build', help = "Build the site from existing content.")
|
||||||
|
new_content = subparsers.add_parser('create', aliases = ['new'], help = "Create a new content file.")
|
||||||
|
new_content.add_argument('filename', type=str, help = "Name of the content file to create.")
|
||||||
|
edit_content = subparsers.add_parser('edit', help = "Edit a content file.")
|
||||||
|
edit_content.add_argument('filename', type=str, help = "Name of the content file to edit.")
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ from config import Config
|
|||||||
from logger import logger
|
from logger import logger
|
||||||
|
|
||||||
def create_content(filename):
|
def create_content(filename):
|
||||||
filename += '.md'
|
filename = Path(f"{Config.CONTENT_DIR}/{filename}.md")
|
||||||
filename = Path(f"{Config.CONTENT_DIR}/{filename}")
|
|
||||||
if not filename.exists():
|
if not filename.exists():
|
||||||
fh = DefaultFrontmatterHeader(filename.stem)
|
fh = DefaultFrontmatterHeader(filename.stem)
|
||||||
logger.debug(f"Creating new content {filename}")
|
logger.debug(f"Creating new content {filename}")
|
||||||
@@ -17,6 +16,10 @@ def create_content(filename):
|
|||||||
def edit_content(filename):
|
def edit_content(filename):
|
||||||
logger.debug(f"Editing content {filename}")
|
logger.debug(f"Editing content {filename}")
|
||||||
editor = os.environ.get('EDITOR', 'vim')
|
editor = os.environ.get('EDITOR', 'vim')
|
||||||
|
# Create the content file if not exists
|
||||||
|
if not Path(f"{Config.CONTENT_DIR}/{filename}.md").exists():
|
||||||
|
create_content(filename)
|
||||||
|
filename = Path(f"{Config.CONTENT_DIR}/{filename}.md")
|
||||||
subprocess.call([editor, filename])
|
subprocess.call([editor, filename])
|
||||||
|
|
||||||
def init_site():
|
def init_site():
|
||||||
|
|||||||
17
hydrogen.py
17
hydrogen.py
@@ -25,7 +25,7 @@ header_image = Config.HEADER_IMAGE or '/static/header.jpg'
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def build_site():
|
def build_site_old():
|
||||||
logger.info(f"Building the '{Config.MAIN_PAGE_TITLE}' site.")
|
logger.info(f"Building the '{Config.MAIN_PAGE_TITLE}' site.")
|
||||||
|
|
||||||
# Recreate the output dir if needed
|
# Recreate the output dir if needed
|
||||||
@@ -73,14 +73,13 @@ def build_site():
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
if args.content:
|
match args.command:
|
||||||
content = args.content or args.edit
|
case "build":
|
||||||
create_content(content)
|
build_site()
|
||||||
edit_content(content)
|
case "init":
|
||||||
if args.build:
|
init_site()
|
||||||
build_site()
|
case "new" | "create" | "edit":
|
||||||
if args.init:
|
edit_content(args.filename)
|
||||||
init_site()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
Reference in New Issue
Block a user