mirror of
http://git.davidovski.xyz/shblg.git
synced 2024-08-15 00:43:48 +00:00
Compare commits
No commits in common. "50074253d03d2f8568d44fd931b84ce212156be9" and "af75a700c52aaca66ffe6db42c4448c2070be21a" have entirely different histories.
50074253d0
...
af75a700c5
8 changed files with 26 additions and 141 deletions
|
@ -1,45 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# add a special header to all entries
|
|
||||||
cat << EOF
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>$1</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>my blog</h1>
|
|
||||||
EOF
|
|
||||||
|
|
||||||
# make this page be the index if it is called with no arguments
|
|
||||||
[ -z "$1" ] && {
|
|
||||||
cat << EOF
|
|
||||||
<h2>blog entries</h2>
|
|
||||||
<ul>
|
|
||||||
EOF
|
|
||||||
# list all the files in the directory
|
|
||||||
for file in *.md; do
|
|
||||||
printf "<li><a href=\"%s\">%s</a></li>" "${file%.*}.html" "$file"
|
|
||||||
done
|
|
||||||
|
|
||||||
cat << EOF
|
|
||||||
</ul>
|
|
||||||
EOF
|
|
||||||
|
|
||||||
} || {
|
|
||||||
# convert the markdown page to html text
|
|
||||||
md2html $1
|
|
||||||
|
|
||||||
# add a back button
|
|
||||||
cat << EOF
|
|
||||||
<span><a href="entries.html">go back to list</a></span>
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
# and a footer
|
|
||||||
cat << EOF
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
EOF
|
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
#!./entries.sh
|
|
||||||
|
|
||||||
# first blog entry
|
|
||||||
|
|
||||||
hello welcome to my test blog. here i will be talking about blah
|
|
||||||
|
|
||||||
## something else
|
|
||||||
|
|
||||||
i probably have something else to say here
|
|
||||||
|
|
||||||
## conclusion
|
|
||||||
|
|
||||||
this is the conclusion, thank you
|
|
|
@ -1,9 +0,0 @@
|
||||||
#!./entries.sh
|
|
||||||
|
|
||||||
# day 2
|
|
||||||
|
|
||||||
this is a second entry to my blog
|
|
||||||
|
|
||||||
i learned how to make text **bold** and *italic*
|
|
||||||
|
|
||||||
wow isnt that ***cool???***
|
|
|
@ -1,8 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# installs m2html and shblg to the system path
|
|
||||||
|
|
||||||
PREFIX=${PREFIX:-/usr}
|
|
||||||
|
|
||||||
install -m755 src/md2html.sh ${PREFIX}/bin/md2html
|
|
||||||
install -m755 src/shblg.sh ${PREFIX}/bin/shblg
|
|
|
@ -6,19 +6,6 @@ cat () {
|
||||||
while IFS= read -r line; do printf "%s\n" "$line"; done < "$1"
|
while IFS= read -r line; do printf "%s\n" "$line"; done < "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
# remove a shebang from the start of the file
|
|
||||||
_remove_shebang () {
|
|
||||||
IFS= read -r line
|
|
||||||
case "$line" in
|
|
||||||
"#!"*) ;;
|
|
||||||
*) printf "%s\n" "$line"
|
|
||||||
esac
|
|
||||||
|
|
||||||
while IFS= read -r line; do
|
|
||||||
printf "%s\n" "$line"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# remove traling whitespace from empty lines
|
# remove traling whitespace from empty lines
|
||||||
#
|
#
|
||||||
_pre_strip () {
|
_pre_strip () {
|
||||||
|
@ -409,8 +396,7 @@ _squash () {
|
||||||
# convert the markdown from stdin into html
|
# convert the markdown from stdin into html
|
||||||
#
|
#
|
||||||
md2html () {
|
md2html () {
|
||||||
_remove_shebang \
|
_pre_strip \
|
||||||
| _pre_strip \
|
|
||||||
| _code \
|
| _code \
|
||||||
| _pre_emph \
|
| _pre_emph \
|
||||||
| _blockquote \
|
| _blockquote \
|
||||||
|
@ -428,7 +414,8 @@ md2html () {
|
||||||
| _h 3 \
|
| _h 3 \
|
||||||
| _h 2 \
|
| _h 2 \
|
||||||
| _h 1 \
|
| _h 1 \
|
||||||
| _squash
|
| _squash \
|
||||||
|
| _html
|
||||||
}
|
}
|
||||||
|
|
||||||
[ -z "$*" ] \
|
[ -z "$*" ] \
|
||||||
|
|
23
src/shblg
Normal file
23
src/shblg
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
INPUT_DIR=blog
|
||||||
|
OUTPUT_DIR=dist
|
||||||
|
PAGE_TEMPLATE=blog/template.html
|
||||||
|
|
||||||
|
while getopts ":o:i:t:" opt; do
|
||||||
|
case "$opt" in
|
||||||
|
o)
|
||||||
|
OUTPUT_DIR=$(realpath $OPTARG)
|
||||||
|
;;
|
||||||
|
i)
|
||||||
|
INPUT_DIR=$(realpath $OPTARG)
|
||||||
|
;;
|
||||||
|
t)
|
||||||
|
PAGE_TEMPLATE=$(realpath $OPTARG)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
for f in ${INPUT_DIR}/*.md; do
|
||||||
|
md2html "$f" > ${OUTPUT_DIR}/$f
|
||||||
|
done
|
48
src/shblg.sh
48
src/shblg.sh
|
@ -1,48 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
INPUT_DIR=blog
|
|
||||||
OUTPUT_DIR=dist
|
|
||||||
PAGE_TEMPLATE=blog/template.html
|
|
||||||
|
|
||||||
while getopts ":o:i:t:" opt; do
|
|
||||||
case "$opt" in
|
|
||||||
o)
|
|
||||||
OUTPUT_DIR=$OPTARG/
|
|
||||||
mkdir -p $OUTPUT_DIR
|
|
||||||
OUTPUT_DIR=$(realpath $OUTPUT_DIR)
|
|
||||||
;;
|
|
||||||
i)
|
|
||||||
INPUT_DIR=$(realpath $OPTARG)
|
|
||||||
;;
|
|
||||||
t)
|
|
||||||
PAGE_TEMPLATE=$(realpath $OPTARG)
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
# process a file to
|
|
||||||
process () {
|
|
||||||
path="${1#$INPUT_DIR}"
|
|
||||||
dirpath="${1%${1##*/}}"
|
|
||||||
out_file="${OUTPUT_DIR}${path}"
|
|
||||||
|
|
||||||
[ -d "$1" ] && {
|
|
||||||
mkdir -p "$out_file"
|
|
||||||
for f in "$1"/*; do
|
|
||||||
process "$f"
|
|
||||||
done
|
|
||||||
return 0
|
|
||||||
} || [ -x "$1" ] && {
|
|
||||||
# execute the file
|
|
||||||
cd $dirpath
|
|
||||||
"$1" > "${out_file%.*}.html"
|
|
||||||
cd -
|
|
||||||
return 0
|
|
||||||
} || {
|
|
||||||
# just output the file as is
|
|
||||||
while IFS= read -r line; do printf "%s\n" "$line"; done < "$1" > "$out_file"
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
process "$INPUT_DIR"
|
|
2
example/index.md → src/test.md
Executable file → Normal file
2
example/index.md → src/test.md
Executable file → Normal file
|
@ -1,5 +1,3 @@
|
||||||
#!/usr/bin/env md2html
|
|
||||||
|
|
||||||
# This is a test md file hello
|
# This is a test md file hello
|
||||||
|
|
||||||
This is *italics* this is **bold** this is ***both*** wow (this is in brackets ssh) and [this is in square brackets not a anchor lol]
|
This is *italics* this is **bold** this is ***both*** wow (this is in brackets ssh) and [this is in square brackets not a anchor lol]
|
Loading…
Reference in a new issue