• Stars
    star
    10
  • Rank 1,807,489 (Top 36 %)
  • Language
    Go
  • License
    GNU General Publi...
  • Created over 5 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[mirror] Go static website generator with asciidoc markup language

Welcome to ciigo

ciigo is a library and a program to write static web server with embedded files using AsciiDoc and Markdown markup format.

As showcase, the following websites are build using ciigo,

ciigo as CLI

ciigo as CLI can convert, generate, and/or serve a directory that contains markup files, as HTML files.

Usage

$ ciigo [-template <file>] [-exclude <regex>] convert <dir>

Scan the "dir" recursively to find markup files (.adoc) and convert them into HTML files. The template "file" is optional, default to embedded HTML template.

$ ciigo [-template <file>] [-exclude <regex>] [-out <file>] generate <dir>

Convert all markup files inside directory "dir" recursively and then embed them into ".go" source file. The output file is optional, default to "ciigo_static.go" in current directory.

$ ciigo [-template <file>] [-exclude <regex>] [-address <ip:port>] serve <dir>

Serve all files inside directory "dir" using HTTP server, watch changes on markup files and convert them to HTML files automatically. If the address is not set, its default to ":8080".

ciigo as library

This section describe step by step instructions on how to build and create pages to be viewed for local development using ciigo.

First, clone the ciigo repository. Let says that we have cloned the ciigo repository into $HOME/go/src/git.sr.ht/~shulhan/ciigo.

Create new Go repository for building a website. For example, in directory $HOME/go/src/remote.tld/user/mysite. Replace "remote.tld/user/mysite" with your private or public repository.

$ mkdir -p $HOME/go/src/remote.tld/user/mysite
$ cd $HOME/go/src/remote.tld/user/mysite

Initialize the Go module,

$ go mod init remote.tld/user/mysite

Create directories for storing our content and a package binary.

$ mkdir -p cmd/mysite
$ mkdir -p _contents

Copy the example of stylesheet and HTML template from ciigo repository,

$ cp $HOME/go/src/git.sr.ht/~shulhan/ciigo/_example/index.css ./_contents/
$ cp $HOME/go/src/git.sr.ht/~shulhan/ciigo/_example/html.tmpl ./_contents/

Create the main Go code inside cmd/mysite,

package main

import (
	"git.sr.ht/~shulhan/ciigo"
	"git.sr.ht/~shulhan/pakakeh.go/lib/memfs"
)

var mysiteFS *memfs.MemFS

func main() {
	opts := &ciigo.ServeOptions{
		ConvertOptions: ciigo.ConvertOptions{
			Root: "_contents",
			HtmlTemplate: "_contents/html.tmpl",
		},
		Address: ":8080",
		Mfs: mysiteFS,
	}
	err := ciigo.Serve(opts)
	if err != nil {
		log.Fatal(err)
	}
}

Create a new markup file index.adoc inside the "_contents" directory. Each directory, or sub directory, should have index.adoc to be able to accessed by browser,

=  Test

Hello, world!

Now run the ./cmd/mysite with DEBUG environment variable set to non-zero,

$ DEBUG=1 go run ./cmd/mysite

Any non zero value on DEBUG environment signal the running program to watch changes in ".adoc" files inside "_contents" directory and serve the generated HTML directly.

Open the web browser at localhost:8080 to view the generated HTML. You should see "Hello, world!" as the main page.

Thats it!

Create or update any ".adoc" files inside "_contents" directory, the program will automatically generated the HTML file. Refresh the web browser to load the new generated file.

Deployment

First, we need to make sure that all markup files inside "_contents" are converted to HTML and embed it into the static Go code.

Create another Go source code, lets save it in internal/generate.go with the following content,

package main

import (
	"log"

	"git.sr.ht/~shulhan/ciigo"
)

func main() {
	opts := &ciigo.EmbedOptions{
		ConvertOptions: ciigo.ConvertOptions{
			Root:           "_contents",
			HtmlTemplate:   "_contents/html.tmpl",
		},
		EmbedOptions: memfs.EmbedOptions{
			PackageName: "main",
			VarName:     "mysiteFS",
			GoFileName:  "cmd/mysite/static.go",
		},
	}
	err := ciigo.GoEmbed(opts)
	if err != nil {
		log.Fatal(err)
	}
}

And then run,

$ go run ./internal

The above command will generate Go source code cmd/mysite/static.go that embed all files inside the "_contents" directory.

Second, build the web server that serve static contents in static.go,

$ go build cmd/mysite

Third, test the web server by running the program and opening localhost:8080 on web browser,

$ ./mysite

Finally, deploy the program to your server.

NOTE: By default, server will listen on address 0.0.0.0 at port 8080. If you need to use another port, you can change it at cmd/mysite/main.go.

That's it!

Limitations and known bugs

Using symlink on ".adoc" file inside Root directory that reference file outside of Root is not supported, yet.

Links

Ciigo repository.

Go module documentation.

License

This software is licensed under GPL 3.0 or later.

Copyright 2022 Shulhan [email protected]

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

More Repositories

1

go-bindata

A small utility which generates Go code from any file. Useful for embedding binary data in a Go program.
Go
186
star
2

pakakeh.go

[mirror] A collection of libraries and tools written in Go.
Go
49
star
3

rescached-go

Resolver (DNS) cache daemon.
Go
32
star
4

hunspell-id

Indonesia hunspell dictionary. Kamus Bahasa Indonesia untuk program hunspell.
Makefile
32
star
5

dsv

The Go library for working with delimited separated value (DSV).
Go
28
star
6

haminer

[mirror] Library and program to parse and forward HAProxy HTTP logs
Go
22
star
7

j2p

A tool to help migrating from JIRA to Phabricator
Go
13
star
8

tabula

A Go library for working with rows, columns, or matrix (deprecated, see https://github.com/shuLhan/share/tree/master/lib/tabula).
Go
11
star
9

go-mining

Data mining with Go.
Go
10
star
10

asciidoctor-go

[mirror] Native Go module for parsing and converting asciidoc markup language.
Go
9
star
11

rescached

Resolver cache daemon (deprecated). See https://github.com/shuLhan/rescached-go for new implementation.
C++
8
star
12

beku

Go simple package manager with GOPATH or vendor
Go
8
star
13

mattermost-integration

Libraries and tools for integrating with Mattermost
Go
7
star
14

sima

Sistem Informasi Manajemen Aset
PHP
7
star
15

arch-docker

Script to create docker images based on Arch Linux on x86_64.
Shell
4
star
16

vos

Vos is a program to process formatted data, i.e. CSV data. Vos is designed to process a large input file, a file where their size is larger than the size of memory, and can be tuned to adapt with your machine environment.
C
4
star
17

wvcgen

Wikipedia vandalism dataset generator
Go
3
star
18

gorankusu

[mirror] The Go module for programmatically run and load testing HTTP services
Go
3
star
19

gotp

[mirror] Command line interface for Time-based One Time Password (TOTP)
Go
2
star
20

thesis

Master Thesis: Detecting Vandalism on English Wikipedia Using LNSMOTE Resampling and Cascaded Random Forest Classifier
TeX
1
star
21

awwan

[mirror] Configuration management software, infrastructure as file and directory layout
Go
1
star
22

mdgo

[mirror] Go static website generator with markdown markup language
Go
1
star
23

gonduit

The Go library for working with Phabricator Conduit API
Go
1
star
24

karajo

[mirror] HTTP workers and manager with web user interface
Go
1
star
25

kait

Go
1
star
26

librextjs

Open source javascript framework.
JavaScript
1
star
27

tekstus

A Go library for working with text (deprecated, see: github.com/shuLhan/lib/text).
Go
1
star
28

libvos

A C-with-class library primarily for manipulating DSV data (reading and writing DSV data in any format), turns out it had more capabilities: DNS protocol, FTP protocol, a simple FTP server, OCI protocol, and reading/writing INI configuration file
C++
1
star
29

share

[Deprecated] A collection of libraries and tools written in Go. This module has been moved to https://git.sr.ht/~shulhan/pakakeh.go
Go
1
star