From c7ebabdc3d32cf3ccc8a1cf5c0332095ddb6d2b5 Mon Sep 17 00:00:00 2001 From: Luis Miguel Lemus Machado Date: Wed, 18 Oct 2023 23:04:52 -0400 Subject: [PATCH 1/6] chore: add vscode setting to use black as default formatter --- .vscode/settings.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c6b7e7a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" + } +} \ No newline at end of file From 61afeab7eb399018ca58b0f3304a44414618c0d5 Mon Sep 17 00:00:00 2001 From: Luis Miguel Lemus Machado Date: Wed, 18 Oct 2023 23:05:28 -0400 Subject: [PATCH 2/6] chore: apply black formatting style --- makesite.py | 128 +++++++++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 56 deletions(-) diff --git a/makesite.py b/makesite.py index 64d105f..db308fe 100644 --- a/makesite.py +++ b/makesite.py @@ -9,7 +9,7 @@ def fread(filename): """Read file and close the file.""" - with open(filename, 'r') as f: + with open(filename, "r") as f: return f.read() @@ -19,23 +19,23 @@ def fwrite(filename, text): if not os.path.isdir(basedir): os.makedirs(basedir) - with open(filename, 'w') as f: + with open(filename, "w") as f: f.write(text) def log(msg, *args): """Log message with specified arguments.""" - sys.stderr.write(msg.format(*args) + '\n') + sys.stderr.write(msg.format(*args) + "\n") def truncate(text, words=25): """Remove tags and truncate text to the specified number of words.""" - return ' '.join(re.sub('(?s)<.*?>', ' ', text).split()[:words]) + return " ".join(re.sub("(?s)<.*?>", " ", text).split()[:words]) def read_headers(text): """Parse headers in text and yield (key, value, end-index) tuples.""" - for match in re.finditer(r'\s*\s*|.+', text): + for match in re.finditer(r"\s*\s*|.+", text): if not match.group(1): break yield match.group(1), match.group(2), match.end() @@ -43,8 +43,8 @@ def read_headers(text): def rfc_2822_format(date_str): """Convert yyyy-mm-dd date string to RFC 2822 format date string.""" - d = datetime.datetime.strptime(date_str, '%Y-%m-%d') - return d.strftime('%a, %d %b %Y %H:%M:%S +0000') + d = datetime.datetime.strptime(date_str, "%Y-%m-%d") + return d.strftime("%a, %d %b %Y %H:%M:%S +0000") def read_content(filename): @@ -53,11 +53,11 @@ def read_content(filename): text = fread(filename) # Read metadata and save it in a dictionary. - date_slug = os.path.basename(filename).split('.')[0] - match = re.search(r'^(?:(\d\d\d\d-\d\d-\d\d)-)?(.+)$', date_slug) + date_slug = os.path.basename(filename).split(".")[0] + match = re.search(r"^(?:(\d\d\d\d-\d\d-\d\d)-)?(.+)$", date_slug) content = { - 'date': match.group(1) or '1970-01-01', - 'slug': match.group(2), + "date": match.group(1) or "1970-01-01", + "slug": match.group(2), } # Read headers. @@ -69,20 +69,18 @@ def read_content(filename): text = text[end:] # Update the dictionary with content and RFC 2822 date. - content.update({ - 'content': text, - 'rfc_2822_date': rfc_2822_format(content['date']) - }) + content.update({"content": text, "rfc_2822_date": rfc_2822_format(content["date"])}) return content def render(template, **params): """Replace placeholders in template with values from params.""" - return re.sub(r'{{\s*([^}\s]+)\s*}}', - lambda match: str(params.get( - match.group(1), match.group(0))), - template) + return re.sub( + r"{{\s*([^}\s]+)\s*}}", + lambda match: str(params.get(match.group(1), match.group(0))), + template, + ) def make_pages(src, dst, layout, **params): @@ -95,20 +93,20 @@ def make_pages(src, dst, layout, **params): page_params = dict(params, **content) # Populate placeholders in content if content-rendering is enabled. - if page_params.get('render') == 'yes': - rendered_content = render(page_params['content'], **page_params) - page_params['content'] = rendered_content - content['content'] = rendered_content + if page_params.get("render") == "yes": + rendered_content = render(page_params["content"], **page_params) + page_params["content"] = rendered_content + content["content"] = rendered_content items.append(content) dst_path = render(dst, **page_params) output = render(layout, **page_params) - log('Rendering {} => {} ...', src_path, dst_path) + log("Rendering {} => {} ...", src_path, dst_path) fwrite(dst_path, output) - return sorted(items, key=lambda x: x['date'], reverse=True) + return sorted(items, key=lambda x: x["date"], reverse=True) def make_list(posts, dst, list_layout, item_layout, **params): @@ -116,71 +114,89 @@ def make_list(posts, dst, list_layout, item_layout, **params): items = [] for post in posts: item_params = dict(params, **post) - item_params['summary'] = truncate(post['content']) + item_params["summary"] = truncate(post["content"]) item = render(item_layout, **item_params) items.append(item) - params['content'] = ''.join(items) + params["content"] = "".join(items) dst_path = render(dst, **params) output = render(list_layout, **params) - log('Rendering list => {} ...', dst_path) + log("Rendering list => {} ...", dst_path) fwrite(dst_path, output) def main(): # Create a new _site directory from scratch. - if os.path.isdir('_site'): - shutil.rmtree('_site') - shutil.copytree('static', '_site') + if os.path.isdir("_site"): + shutil.rmtree("_site") + shutil.copytree("static", "_site") # Default parameters. params = { - 'base_path': '', - 'subtitle': 'Lorem Ipsum', - 'author': 'Admin', - 'site_url': 'http://localhost:8000', - 'current_year': datetime.datetime.now().year + "base_path": "", + "subtitle": "Lorem Ipsum", + "author": "Admin", + "site_url": "http://localhost:8000", + "current_year": datetime.datetime.now().year, } # If params.json exists, load it. - if os.path.isfile('params.json'): - params.update(json.loads(fread('params.json'))) + if os.path.isfile("params.json"): + params.update(json.loads(fread("params.json"))) # Load layouts. - page_layout = fread('layout/page.html') - post_layout = fread('layout/post.html') - list_layout = fread('layout/list.html') - item_layout = fread('layout/item.html') - feed_xml = fread('layout/feed.xml') - item_xml = fread('layout/item.xml') + page_layout = fread("layout/page.html") + post_layout = fread("layout/post.html") + list_layout = fread("layout/list.html") + item_layout = fread("layout/item.html") + feed_xml = fread("layout/feed.xml") + item_xml = fread("layout/item.xml") # Combine layouts to form final layouts. post_layout = render(page_layout, content=post_layout) list_layout = render(page_layout, content=list_layout) # Create site pages. - make_pages('content/_index.html', '_site/index.html', - page_layout, **params) - make_pages('content/[!_]*.html', '_site/{{ slug }}/index.html', - page_layout, **params) + make_pages("content/_index.html", "_site/index.html", page_layout, **params) + make_pages( + "content/[!_]*.html", "_site/{{ slug }}/index.html", page_layout, **params + ) # Create blogs. - blog_posts = make_pages('content/blog/*.html', - '_site/blog/{{ slug }}/index.html', - post_layout, blog='blog', **params) + blog_posts = make_pages( + "content/blog/*.html", + "_site/blog/{{ slug }}/index.html", + post_layout, + blog="blog", + **params + ) # Create blog list pages. - make_list(blog_posts, '_site/blog/index.html', - list_layout, item_layout, blog='blog', title='Blog', **params) + make_list( + blog_posts, + "_site/blog/index.html", + list_layout, + item_layout, + blog="blog", + title="Blog", + **params + ) # Create RSS feeds. - make_list(blog_posts, '_site/blog/rss.xml', - feed_xml, item_xml, blog='blog', title='Blog', **params) + make_list( + blog_posts, + "_site/blog/rss.xml", + feed_xml, + item_xml, + blog="blog", + title="Blog", + **params + ) # Test parameter to be set temporarily by unit tests. _test = None -if __name__ == '__main__': +if __name__ == "__main__": main() From a392778ad07f4d4715a46cbb9c0ea8c9d5472063 Mon Sep 17 00:00:00 2001 From: Luis Miguel Lemus Machado Date: Thu, 19 Oct 2023 10:01:54 -0400 Subject: [PATCH 3/6] feat: add manually crafted SVG logo --- media/logo.svg | 196 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 media/logo.svg diff --git a/media/logo.svg b/media/logo.svg new file mode 100644 index 0000000..01b4b7d --- /dev/null +++ b/media/logo.svg @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 21b6995ebb6a427c6a582426e159b4808b7781b2 Mon Sep 17 00:00:00 2001 From: Luis Miguel Lemus Machado Date: Thu, 19 Oct 2023 10:02:22 -0400 Subject: [PATCH 4/6] feat: add favicon --- static/favicon.ico | Bin 0 -> 1662 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 static/favicon.ico diff --git a/static/favicon.ico b/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..d3e38341d48d2f84e27c048bd1395028580a42e9 GIT binary patch literal 1662 zcmZQzU<5(~0|6k(!jQqnz#zuJz@P!d20)wu#2|5eKvPqb!OqT(AtWS(p|-Y`VcD`} z47+#l#;0Wv$T7RX0nnphHps&aENO7yz`y`z18J&?hd^xx+v}Q^1~VT_gX{tUpgSCp zX%HI(XeEwr?kFEM{OJ%Lu!QG;7SA*lXH Date: Thu, 19 Oct 2023 10:36:48 -0400 Subject: [PATCH 5/6] build: add makesite custom workflow --- .github/workflows/makesite.yml | 53 ++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/makesite.yml diff --git a/.github/workflows/makesite.yml b/.github/workflows/makesite.yml new file mode 100644 index 0000000..eb0dc90 --- /dev/null +++ b/.github/workflows/makesite.yml @@ -0,0 +1,53 @@ +name: Build with makesite.py and deploy to Pages + +on: + pull_request: + branches: ["main"] + + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: "pages" + cancel-in-progress: false + +defaults: + run: + shell: bash + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Ensure python is available + run: | + sudo apt-get -y update && sudo apt-get -y install python3 python-is-python3 + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: recursive + - name: Setup Pages + id: pages + uses: actions/configure-pages@v3 + - name: Build with makesite.py + run: | + python makesite.py + - name: Upload artifact + uses: actions/upload-pages-artifact@v2 + with: + path: ./_site + + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v2 From 0c0016d7e9c2de3c1d248cd5f7e87fc01f47e283 Mon Sep 17 00:00:00 2001 From: Luis Miguel Lemus Machado Date: Thu, 19 Oct 2023 10:44:12 -0400 Subject: [PATCH 6/6] build: disabling pull_request event for workflow --- .github/workflows/makesite.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/makesite.yml b/.github/workflows/makesite.yml index eb0dc90..3b07a50 100644 --- a/.github/workflows/makesite.yml +++ b/.github/workflows/makesite.yml @@ -1,9 +1,6 @@ name: Build with makesite.py and deploy to Pages on: - pull_request: - branches: ["main"] - workflow_dispatch: permissions: