Skip to content

Commit

Permalink
support md-based titles, allow for modified env roots
Browse files Browse the repository at this point in the history
  • Loading branch information
Perfect5th committed Jan 21, 2024
1 parent 9045373 commit a4d4d03
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 11 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ jobs:
run: |
sudo apt update
sudo apt install markdown
echo ${{ steps.deployment.outputs.page_url }}
SITE_ROOT="/simple-site" ./convert.sh
./convert.sh
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ For my actual website source see [this repo][1].
2. Make sure github pages is turned on and the source is set to "Github Actions"
3. Put your markdown files in `./markdown`, make sure they end with `.md`
4. Replace the `favicon.ico` of my face with your own, or delete it
5. Commit them and push
5. Change `SITE_ROOT` in `./env` to match where your site will be served
6. Commit and push

**Note**: If your markdown file starts with a H1 header, That header will also be used as the title of the page.

## Custom CSS and Javascript

Expand Down
32 changes: 26 additions & 6 deletions convert.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
#!/usr/bin/env sh

# A simple-site converted. Wraps the html produced from markdown in a few tags
# A simple-site convertor. Wraps the html produced from markdown in a few tags
# to make it web-servable.

. ./env

FILES=$(find ./markdown -type f -name '*.md')

rm -rf ./_site
mkdir -p ./_site

for FILE in $FILES; do
HTML_PATH=$(echo "$FILE" | sed -e 's/\.md$/\.html/' | sed -e 's/^\.\/markdown/\.\/_site/')
convert_file() {
HTML_PATH=$(echo "$1" | sed -e 's/\.md$/\.html/' | sed -e 's/^\.\/markdown/\.\/_site/')

mkdir -p "$(dirname "$HTML_PATH")"

FIRST_LINE=$(head -n 1 "$1")

if echo "$FIRST_LINE" | grep -q '^# '; then
PAGE_TITLE=$(echo "$FIRST_LINE" | cut -c3-)
else
PAGE_TITLE=$SITE_TITLE
fi

echo "Creating $HTML_PATH"
sed -e "s:{{SITE_ROOT}}:$SITE_ROOT:g" ./templates/base.html > "$HTML_PATH"
markdown --html4tags "$FILE" >> "$HTML_PATH"
sed -e "s:{{SITE_ROOT}}:$SITE_ROOT:g" ./templates/base.html | \
sed -e "s:{{PAGE_TITLE}}:$PAGE_TITLE:g" \
> "$HTML_PATH"
markdown --html4tags "$1" >> "$HTML_PATH"
cat ./templates/close.html >> "$HTML_PATH"
}

for FILE in $FILES; do
convert_file "$FILE" &
done

wait

mkdir -p ./_site/css
mkdir -p ./_site/js
cp ./css/base.css ./_site/css/base.css
Expand Down
2 changes: 2 additions & 0 deletions env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export SITE_ROOT="/simple-site"
export SITE_TITLE="Simple Site"
5 changes: 4 additions & 1 deletion markdown/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Homepage
# Simple Site

Welcome to the homepage!

There's a subpage [here][1].

[1]: subpage "A test subpage"
4 changes: 4 additions & 0 deletions markdown/subpage/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Subpage

This is a subpage. You can go [back to home](../ "Back home").

2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<title>Simple Site</title>
<title>{{PAGE_TITLE}}</title>
<meta name="description" content="A simple, markdown-derived website.">
<link rel="icon" href="{{SITE_ROOT}}/favicon.ico">
<link rel="stylesheet" href="{{SITE_ROOT}}/css/base.css">
Expand Down

0 comments on commit a4d4d03

Please sign in to comment.