Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add invoke tasks #11

Merged
merged 3 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: latest
hugo-version: 0.112.3

- name: Build
run: hugo --minify
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoke
35 changes: 35 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import datetime
import webbrowser

from invoke import task, Context


@task
def build(ctx: Context) -> None:
ctx.run("hugo --minify")


@task
def dev(ctx: Context) -> None:
webbrowser.open('http://localhost:1313/')
ctx.run("hugo server -D")


@task
def add_blog(ctx: Context, title: str, prefix: str | None = None) -> None:
prefix = prefix or _get_timestamp()
title = title.replace(" ", "-").lower()
path = f"blog/{prefix}-{title}"

ctx.run(f"hugo new --kind post {path}")

@task
def add_til(ctx: Context, title: str, prefix: str | None = None) -> None:
prefix = prefix or _get_timestamp()
title = title.replace(" ", "-").lower()
path = f"til/{prefix}-{title}"

ctx.run(f"hugo new --kind post {path}")

def _get_timestamp() -> str:
return datetime.datetime.now().strftime("%Y-%m-%d")
Loading