clean up existing unused files
This commit is contained in:
parent
f184e61036
commit
ee4b001300
@ -24,6 +24,7 @@ jobs:
|
|||||||
- name: Build only
|
- name: Build only
|
||||||
uses: shalzz/zola-deploy-action@v0.19.1
|
uses: shalzz/zola-deploy-action@v0.19.1
|
||||||
env:
|
env:
|
||||||
|
BUILD_DIR: sites/ewpratten.com
|
||||||
BUILD_ONLY: true
|
BUILD_ONLY: true
|
||||||
BUILD_FLAGS: --drafts
|
BUILD_FLAGS: --drafts
|
||||||
|
|
||||||
@ -46,6 +47,7 @@ jobs:
|
|||||||
- name: Build only
|
- name: Build only
|
||||||
uses: shalzz/zola-deploy-action@v0.19.1
|
uses: shalzz/zola-deploy-action@v0.19.1
|
||||||
env:
|
env:
|
||||||
|
BUILD_DIR: sites/ewpratten.com
|
||||||
BUILD_ONLY: true
|
BUILD_ONLY: true
|
||||||
|
|
||||||
- name: Publish to Cloudflare Pages
|
- name: Publish to Cloudflare Pages
|
||||||
@ -54,6 +56,6 @@ jobs:
|
|||||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
projectName: ewpratten
|
projectName: ewpratten
|
||||||
directory: public
|
directory: sites/ewpratten.com/public
|
||||||
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
|
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
|
||||||
wranglerVersion: '2'
|
wranglerVersion: '2'
|
2
.vscode/tasks.json
vendored
2
.vscode/tasks.json
vendored
@ -8,7 +8,7 @@
|
|||||||
"type": "shell",
|
"type": "shell",
|
||||||
"command": "zola",
|
"command": "zola",
|
||||||
"options": {
|
"options": {
|
||||||
"cwd": "${workspaceFolder}"
|
"cwd": "${workspaceFolder}/sites/ewpratten.com"
|
||||||
},
|
},
|
||||||
"args": [
|
"args": [
|
||||||
"serve",
|
"serve",
|
||||||
|
@ -1 +0,0 @@
|
|||||||
./static/_redirects
|
|
@ -1 +0,0 @@
|
|||||||
python-frontmatter
|
|
@ -1,37 +0,0 @@
|
|||||||
import re
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
REPO_ROOT = Path(__file__).parent.parent
|
|
||||||
|
|
||||||
# Find all MD and HTML files
|
|
||||||
md_files = list(REPO_ROOT.rglob("*.md"))
|
|
||||||
html_files = list(REPO_ROOT.rglob("*.html"))
|
|
||||||
|
|
||||||
# Ignore any files in the `public` directory
|
|
||||||
md_files = [f for f in md_files if "public" not in f.parts]
|
|
||||||
html_files = [f for f in html_files if "public" not in f.parts]
|
|
||||||
|
|
||||||
# Result storage
|
|
||||||
external_assets = set()
|
|
||||||
|
|
||||||
# Find Markdown images
|
|
||||||
for file in md_files:
|
|
||||||
body = file.read_text()
|
|
||||||
for match in re.finditer(r"!\[.*?\]\((.*?)\)", body):
|
|
||||||
link = match.group(1)
|
|
||||||
if link.startswith("http"):
|
|
||||||
external_assets.add((file, link))
|
|
||||||
|
|
||||||
# Search HTML
|
|
||||||
for file in html_files:
|
|
||||||
body = file.read_text()
|
|
||||||
for match in re.finditer(r'src="(.*?)"', body):
|
|
||||||
link = match.group(1)
|
|
||||||
if link.startswith("http"):
|
|
||||||
external_assets.add((file, link))
|
|
||||||
|
|
||||||
# Print all external assets
|
|
||||||
for file_path, link in external_assets:
|
|
||||||
# Strip the prefix off the file path
|
|
||||||
file_path = file_path.relative_to(REPO_ROOT)
|
|
||||||
print(f"{file_path}:\t{link}")
|
|
@ -1,66 +0,0 @@
|
|||||||
import argparse
|
|
||||||
import sys
|
|
||||||
import re
|
|
||||||
import frontmatter
|
|
||||||
import yaml
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
BLOG_POST_RE = re.compile(r"^\d{4}-\d+-\d+-(.*)\.md$")
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
|
||||||
# Handle program arguments
|
|
||||||
ap = argparse.ArgumentParser(
|
|
||||||
description="Fixes the `aliases` field in the front matter of markdown files"
|
|
||||||
)
|
|
||||||
ap.add_argument(
|
|
||||||
"--root",
|
|
||||||
type=Path,
|
|
||||||
default=Path(__file__).parent.parent / "content" / "blog",
|
|
||||||
help="The root directory to search for markdown files",
|
|
||||||
)
|
|
||||||
args = ap.parse_args()
|
|
||||||
|
|
||||||
# Find all markdown files
|
|
||||||
md_files = list(args.root.glob("**/*.md"))
|
|
||||||
print(f"Found {len(md_files)} markdown files")
|
|
||||||
|
|
||||||
# Handle each file
|
|
||||||
for file in md_files:
|
|
||||||
print(f"Processing: {file}")
|
|
||||||
|
|
||||||
# Determine what the alias path should be
|
|
||||||
title_matches = BLOG_POST_RE.match(file.name)
|
|
||||||
if not title_matches:
|
|
||||||
print("Skipping file, not a blog post")
|
|
||||||
continue
|
|
||||||
|
|
||||||
title = title_matches.group(1)
|
|
||||||
correct_alias = f"/blog/{title.lower()}"
|
|
||||||
print("Correct alias:", correct_alias)
|
|
||||||
|
|
||||||
# Load and parse the frontmatter
|
|
||||||
post = frontmatter.load(file)
|
|
||||||
|
|
||||||
# Get the list of aliases
|
|
||||||
aliases = post.metadata.get("aliases", [])
|
|
||||||
|
|
||||||
# If the alias is already correct, skip it
|
|
||||||
if correct_alias in aliases:
|
|
||||||
print("Found correct alias")
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Otherwise, add the correct alias
|
|
||||||
aliases.append(correct_alias)
|
|
||||||
|
|
||||||
# Write out the new frontmatter
|
|
||||||
post.metadata["aliases"] = aliases
|
|
||||||
file_contents = frontmatter.dumps(post, sort_keys=False)
|
|
||||||
file_contents += "\n"
|
|
||||||
file.write_text(file_contents)
|
|
||||||
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
sys.exit(main())
|
|
Loading…
x
Reference in New Issue
Block a user