~skiqqy/gwiki

50323dce3a599171986426fd679c59377b9607b5 — Stephen Cochrane 4 months ago 70dfc8d
Updated readme, and added helper script
2 files changed, 124 insertions(+), 4 deletions(-)

M README.md
A setup
M README.md => README.md +43 -4
@@ 1,10 1,30 @@
# gwiki

> Simple git based wiki, using mkdocs
> Simple git curated wiki

## Concept

I like the concept of simple statically generated websites, although they lack
the feeling of "live content", that is, content can be updated anywhere, easily.

gwiki is simple, in that all it is, is a docker image which handles hosting of
a wiki (and sub wikis), which themselves are hosted in public (or private) git
repositories.

When gwiki detects a change in any wiki (be it the root, or sub wikis), they are
rebuilt, and redeployed.

The keen reader may realise that this allows us to maintain a wiki (or
arbitrary website) only through the actions of pushing updates to a repository.

The nice thing is gwiki doesnt _have_ to be a wiki, it can be a basic website
as well, it is essentially the concept of the dev server of my
[website](https://skiqqy.xyz), but improved.

## Building

To Build the image, something like the following will work (replace podman with docker if you use docker):
To Build the image, something like the following will work (replace podman with
docker if you use docker):
```
$ podman build -t gwiki:latest .
```


@@ 15,9 35,28 @@ To run the image, the following is suitable
$ podman run --name gwiki \
		-p 80:80 \
		--env CONFIG_HOME=https://some.website/repo.git \
		--env TIMER=60 \
		gwiki:latest
```

## About
Notable environment variables
* CONFIG\_HOME : The url to the root wiki, which _should_ contain a `config`
  file, which is just an array containing urls to other repos to be hosted.
* TIMER : Time in seconds between checking if a rebuild must occur.

## Getting Started

This repo ships with a basic "root" wiki script, to get started, the following
will suffice.
```
$ bash <(curl https://git.sr.ht/~skiqqy/gwiki/blob/master/setup)
```
Once the project has been creating, the only file of importance is `config`
located in the root of the project that was just created.

This config file consists of a single array, with each element consisting of a
url to a repository (this repository can be anything, but typically it would be
a mkdocs project), gwiki then pulls, builds, and deploys this wiki.

TODO
Then if you wish to add a wiki to be deployed, you simply have to update
`config` appropriatly, and push the changes, gwiki does the rest!

A setup => setup +81 -0
@@ 0,0 1,81 @@
#!/usr/bin/env bash
# Setup script for gwiki, creats root wiki project

usage()
{
	cat << EOF
$(basename "$0") ~ Simple gwiki setup script

   Usage:
      $ $(basename "$0") [OPTIONS] COMMAND [ARGS...]

   Options:
      -h   Shows this message

   Commands:
      new

EOF
	exit "${1:-0}"
}

# Print a prompt with $1, returns 0 if user inputs yes
yn()
{
	read -rp "$1? (Y/N) " input
	if [[ ! $input =~ ^(y|Y)((ES)|(es))?$ ]]
	then
		return 1
	fi
}

# Create a basic wiki repo
ginit()
{
	local proj
	proj="${1:-wiki/}"

	if yn "Create project $proj "
	then
		mkdocs new "$proj"
		pushd "$proj" || return 1
			git init
			printf '#!/usr/bin/env bash\nwikis=( ) # Add urls to other wikis in this bash array.\n' > config
			printf 'site/\n' > .gitignore
			git add . && git commit -m "init"
		popd || return 1
	fi
}

main()
{
	while getopts 'h' opt
	do
		case "$opt" in
			h)
				usage
				;;
			*)
				usage 1
				;;
		esac
	done
	shift "$((OPTIND-1))" # Get rid of parsed options

	local com
	com="$1"
	shift 1
	case "$com" in
		new|init)
			ginit "$@"
			;;
		'')
			ginit # By default, create the most default of projects
			;;
		*)
			usage 1
			;;
	esac
}

main "$@"