kaveh

a simple website generator
git clone git://mahdi.pw/kaveh.git
Log | Files | Refs | README | LICENSE

commit 20186056f54c6c18be25dac192722205f6e980b0
parent 4b88d144f58812dd554bc27a7eac4d1f13e67a83
Author: Mahdi Mirzade <[email protected]>
Date:   Tue, 15 Mar 2022 07:21:23 +0330

Update

Diffstat:
MKaveh | 88++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
MREADME.md | 39++++++++++++++++++++++++++++++++++++++-
Aout/blog/index.md | 5+++++
Aout/index.md | 23+++++++++++++++++++++++
Msrc/index.md | 8+-------
5 files changed, 143 insertions(+), 20 deletions(-)

diff --git a/Kaveh b/Kaveh @@ -1,13 +1,67 @@ #!/usr/bin/env bash - -# Source config file -export KVH_CONFIG_FILE="./Kaveh.cfg" -[[ -f "$KVH_CONFIG_FILE" ]] && source "$KVH_CONFIG_FILE" +# +# Kaveh is a simple website generator. +# https://github.com/MahdyMirzade/Kaveh +# +# Kaveh's version/copyright +KVH_VERSION="1.0.0" +KVH_COPYRIGHT="Copyright (C) 2021 Mahdy Mirzade" # Default configuration -export KVH_SRC="${KVH_INPUT_DIR:-./src}" -export KVH_DST="${KVH_OUTPUT_DIR:-./out}" -export KVH_DATETIME="${KVH_DATETIME:-%d %B %Y %H:%M:%S}" +KVH_SRC="${PWD}/src" +KVH_DST="${PWD}/out" +KVH_TPL="${PWD}/tpl" +KVH_DATETIME="%d %B %Y %H:%M:%S" + +# Help text +usage(){ + cat <<EOF +$0 [-i SOURCE_DIR] [-o OUTPUT_DIR] [-t TEMPLATE_DIR] [-d DATETIME_FORMAT] +EOF + exit +} + +version(){ + cat <<EOF + + _ __ _ Kaveh v$KVH_VERSION +| |/ /__ ___ _____| |__ $KVH_COPYRIGHT +| ' // _\` \ \ / / _ \ '_ \ +| . \ (_| |\ V / __/ | | | This program may be freely redistributed under +|_|\_\__,_| \_/ \___|_| |_| the terms of the GNU General Public License. + +EOF + exit +} + +# Custom options +while getopts :hvi:o:t:d: flag; do + case "${flag}" in + i) KVH_SRC=${OPTARG};; + o) KVH_DST=${OPTARG};; + t) KVH_TPL=${OPTARG};; + d) KVH_DATETIME=${OPTARG};; + v) version;; + h|*) usage;; + esac +done + +# Check KVH_* +check_config(){ + KILL_PROGRAM="FALSE" + if [[ ! -e "$KVH_SRC" ]]; then + echo "ERROR: '$KVH_SRC' doesn't exist." + KILL_PROGRAM="TRUE" + fi + if [[ ! -e "$KVH_TPL" ]]; then + echo "ERROR: '$KVH_TPL' doesn't exist." + KILL_PROGRAM="TRUE" + fi + if [[ "$KILL_PROGRAM" == "TRUE" ]]; then + echo "Terminating program..." + exit + fi +} # Find all pre-existed dirs find_dirs(){ @@ -31,7 +85,7 @@ find_mds(){ KVH_MARKDOWNS=() while IFS= read -d $'\n' -r file ; do KVH_MARKDOWNS=("${KVH_MARKDOWNS[@]}" "$file") - done < <(find "$KVH_SRC" -type f -perm /u=r -name "*.md") + done < <(find "$KVH_SRC" -type f -perm /u=r -iname "*.md") } # Get Markdown comments from file @@ -54,9 +108,9 @@ make_mds(){ POST_COMMENTS=$(parse_md_comments "$KVH_FILE") TITLE=$(parse_md_variables "Title" "$POST_COMMENTS") DESC=$(parse_md_variables "Description" "$POST_COMMENTS") - H=$(cat "./tpl/header.html") + H=$(cat "${KVH_TPL}/header.html") C=$(markdown "$KVH_FILE") - F=$(cat "./tpl/footer.html") + F=$(cat "${KVH_TPL}/footer.html") D=$(date -r "$KVH_FILE" "+$KVH_DATETIME") KVH_CONTENT="$H $C @@ -69,5 +123,15 @@ $F" } # Main program -make_dirs -make_mds +main(){ + check_config + make_dirs + make_mds + # Copy the rest of files/assets + while IFS= read -d $'\n' -r file ; do + dest="$KVH_DST/${file#$KVH_SRC/}" + if [[ -e "$dest" ]]; then echo "'$dest' Already exists."; continue; else cp "$file" "$dest"; fi + done < <(find "$KVH_SRC" -type f -perm /u=r -print) +} + +main diff --git a/README.md b/README.md @@ -1,2 +1,39 @@ # Kaveh -A simple blog. +Kaveh is a simple website generator, it aims to generate static html files from markdown files, no databases and bloat-web, just texts. + +## Dependencies +Kaveh requires a markdown parser in your `$PATH`, to install it: +```bash +pacman -S discount +``` + +## Installation +```bash +git clone https://github.com/MahdyMirzade/gip.git +cp Kaveh/Kaveh /usr/bin +Kaveh -v +``` +> You may need to run some of these commands with root permissions. (sudo) + +## Usage +| Method | Description | +| --- | --- | +| **-i** | The source directory, where to read markdowns and copy other assets from. | +| **-o** | The output directory, where to generate html files and copy other files to. | +| **-t** | The template directory, where the `header.html` and `footer.html` is. | + +### Example of usage +Example of `build.sh` and scripting: +```bash +Kaveh -i /var/doc/mahdym.ir -o /var/www/mahdym.ir +``` +> Then just run the `build.sh` file, whenever you've updated the `/var/doc/mahdym.ir`'s files. + +### Example of output +I've made an example so you can understand what's going on, take a look at the `./src/index.md`, then open the `./out/index.html` in your browser. + +## How to edit pre-existing files? +1. Clone this repository and enter it. +2. Edit the files in `src` directory. +3. Write your other documents with `.md` in the end, like: `index.md`. +4. Go back to your parent directory, and generate your website into `./out` using: ```Kaveh -i ./src -o ./out``` diff --git a/out/blog/index.md b/out/blog/index.md @@ -0,0 +1,5 @@ +# What is this? +This is my simple template to create minimal websites. + +## How do you use it? +I write my blog posts like `blog/*.md`, using Markdown, It's easier for me to read and write. diff --git a/out/index.md b/out/index.md @@ -0,0 +1,23 @@ +<!---------------KVH---------------- +Title: Kaveh | Home Page +Description: This is about Kaveh. +-----------------------------------> + +<div style="text-align: center;"><img src="./logo.png"></div> + +# What is this? +This is my simple template to create minimal websites. + +## How do you use it? +I write my blog posts like `blog/*.md`, using Markdown, It's easier for me to read and write. + +## Team ![GitHub contributors](https://img.shields.io/github/contributors/mahdymirzade/gip) +This project is maintained by the following people and a bunch of [awesome contributors](https://github.com/MahdyMirzade/gip/graphs/contributors). + +| [![Mahdy Mirzade](https://github.com/mahdymirzade.png?size=100)](https://github.com/mahdymirzade) | +| --- | +| [Mahdy Mirzade](https://github.com/mahdymirzade) | + +## Donate +You can use [this page](https://git.io/JB2BO) to find more about supporting this project. + diff --git a/src/index.md b/src/index.md @@ -11,12 +11,6 @@ This is my simple template to create minimal websites. ## How do you use it? I write my blog posts like `blog/*.md`, using Markdown, It's easier for me to read and write. -## Team ![GitHub contributors](https://img.shields.io/github/contributors/mahdymirzade/gip) -This project is maintained by the following people and a bunch of [awesome contributors](https://github.com/MahdyMirzade/gip/graphs/contributors). - -| [![Mahdy Mirzade](https://github.com/mahdymirzade.png?size=100)](https://github.com/mahdymirzade) | -| --- | -| [Mahdy Mirzade](https://github.com/mahdymirzade) | - ## Donate You can use [this page](https://git.io/JB2BO) to find more about supporting this project. +