Skip to content

Commit

Permalink
add empty blog post (template)
Browse files Browse the repository at this point in the history
(lazy - should use index template)
  • Loading branch information
alifeee committed Sep 5, 2024
1 parent 0c27e93 commit c26cb40
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 2 deletions.
42 changes: 42 additions & 0 deletions 1970/01/empty/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
# generate HTML from markdown,
# then replace all lines between START_CONTENT and END_CONTENT with this HTML
# in the file INDEX_FILE
# requires marked https://github.com/markedjs/marked
# npm install -g marked
# usage:
# ./build.sh content.md

if [ -z $1 ]; then
CONTENT_FILE="${PWD##*/}.md"
echo "transforming CONTENT_FILE"
else
CONTENT_FILE="$1"
fi

INDEX_FILE="index.html"
TEMP_FILE="index.html.temp"
START_CONTENT="<!-- !!start content!! -->"
END_CONTENT="<!-- !!end content!! -->"

original_html=$(cat $INDEX_FILE)

html=$(marked -i "$CONTENT_FILE")

# get line numbers of START_CONTENT and END_CONTENT
start=$(echo "${original_html}" | grep -n "${START_CONTENT}" | cut -d : -f1)
end=$(echo "${original_html}" | grep -n "${END_CONTENT}" | cut -d : -f1)

if [ -z $start ] || [ -z $end ]; then
echo "could not find start/end content tags"
echo "start: <$start>, end: <$end>"
exit 1
fi

rm -f $TEMP_FILE
echo "${original_html}" | awk 'NR <= '"${start}"'' >> $TEMP_FILE
echo "${html}" >> $TEMP_FILE
echo "${original_html}" | awk 'NR >= '"${end}"'' >> $TEMP_FILE

cat $TEMP_FILE > $INDEX_FILE
rm -f $TEMP_FILE
3 changes: 3 additions & 0 deletions 1970/01/empty/empty.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Empty

Not much content here :)
131 changes: 131 additions & 0 deletions 1970/01/empty/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>alifeee - UK Railcards</title>
<!-- browser metas -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="description"
content="UK Railcards and all the differences between the 16-25 and 26-30 Railcard"
/>

<!-- embed metas - https://ogp.me/ -->
<meta property="og:title" content="UK Railcards" />
<meta property="og:type" content="website" />
<meta property="og:site" content="alifeee's blog" />
<meta property="og:url" content="https://blog.alifeee.co.uk/railcards" />
<meta
property="og:image"
content="https://blog.alifeee.co.uk/railcards/og-image.png"
/>
<meta
property="og:description"
content="UK Railcards and all the differences between the 16-25 and 26-30 Railcard"
/>
<meta property="og:locale" content="en_GB" />

<!-- styling -->
<!-- favicon -->
<link rel="icon" type="image/png" href="/favicon.png" />
<!-- external stylesheets -->
<!-- from https://cdn.jsdelivr.net/gh/sindresorhus/github-markdown-css@4/github-markdown.min.css -->
<link rel="stylesheet" href="/github-markdown.min.css" />
<!-- from https://cdn.jsdelivr.net/gh/PrismJS/prism@1/themes/prism.min.css -->
<link rel="stylesheet" href="/prism.min.css" />
<!-- my stylesheets -->
<link rel="stylesheet" href="/stylesheet.css" />
<link rel="stylesheet" href="/stylesheet_md.css" />
<!-- specific to this page styles -->
<style></style>

<!-- libraries -->
<!-- anchorjs: https://github.com/bryanbraun/anchorjs -->
<script type="module">
import "/anchor.min.js";
document.addEventListener("DOMContentLoaded", function (event) {
let tags = ["h2", "h3", "h4", "h5", "h6"];
anchors.add("#content " + tags.join(", #content "));
});
</script>
<!-- prismjs https://github.com/PrismJS/prism -->
<!-- from https://cdn.jsdelivr.net/gh/PrismJS/prism@1/prism.min.js -->
<script src="/prism.min.js"></script>

<!-- word-count component from word-count.js -->
<script src="/word-count.js"></script>

<!-- htmx -->
<script
src="/htmx.min.js"
integrity="sha384-rgjA7mptc2ETQqXoYC3/zJvkU7K/aP44Y+z7xQuJiVnB/422P/Ak+F/AqFR7E4Wr"
crossorigin="anonymous"
></script>

<!-- extra scripts -->
<script type="module"></script>
</head>

<body>
<header>
<a href="/">
<h1>alifeee's blog</h1>
</a>
<a id="rss" href="/feed.xml">
<img alt="_RSS_" src="/icons/rss.svg" />
</a>
</header>

<main>
<section id="content" class="markdown-body">
<!-- !!start content!! -->
<h1>Empty</h1>
<p>Not much content here :)</p>
<!-- !!end content!! -->
</section>
<hr />

<section id="comments">
<h2>Comments</h2>
<p>
Email me →
<a href="mailto:alifeee.web@outlook.com">alifeee.web@outlook.com</a>
:)
</p>
<p>
Message me on any social media →
<a href="https://linktr.ee/alifeee">https://linktr.ee/alifeee</a> :)
</p>
</section>

<section id="similar">
<h1>
Similar posts
<a
href="https://github.com/alifeee/blog?tab=readme-ov-file#similar-posts"
>(?)</a
>
</h1>
<div hx-get="./similar.html" hx-trigger="load" hx-swap="afterend"></div>
</section>
</main>

<footer>
<div class="links">
<a href="https://github.com/alifeee/blog">
<img alt="_GitHub_" src="/icons/github.svg" />
<span class="text">GitHub</span>
</a>
<a href="https://linktr.ee/alifeee">
<img alt="_Linktree_" src="/icons/linktree-logo-icon.svg" />
<span class="text">Linktree</span>
</a>
<a href="mailto:alifeee.web@outlook.com">
<img alt="_Email_" src="/icons/envelope-solid.svg" />
<span class="text">Email</span>
</a>
</div>
<a class="backlink" href="/">Back to main page</a>
</footer>
</body>
</html>
3 changes: 1 addition & 2 deletions utilities.py/post_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ def get_all_posts() -> List[Post]:
relative_url = post.find("a", class_="link")["href"]
# md url is f"{relative_url}/{relative_url}.md"
# with "./\" stripped from relative_url
title_filename = relative_url.lstrip("./")
md_url = f"{relative_url}/{title_filename}.md"
md_url = os.path.join(relative_url, os.path.basename(relative_url) + ".md")

date_str = post.find("time")["datetime"]
date = datetime.strptime(date_str, "%Y-%m-%d")
Expand Down

0 comments on commit c26cb40

Please sign in to comment.