This ~300-line POSIX-compliant shell script is a flexible static site generator designed to transform content into a fully functional and transparent website. The generator's core philosophy is file-based modularity, where each piece of content in a directory is generated into a single file. It combines dynamic content generation with version control metadata to create a Git-driven static website.
-
D.R.Y. - Do Not Repeat Yourself
- Configuration Management: The script uses a global conf file to define global settings, such as (
BUILD_DIR
,CSS_FILE
,PICS_DIR
,site_lang
,default_footer
,site_description
...), and other globally defined custom variables. Individual files can also include their ownconf
file to override global variables or file-specific Git metadata. - Dynamic Placeholder Replacement: Placeholders like
${author_name}
,${date_created}
,${date_modified}
, and${title}
are dynamically replaced with:- Git Metadata: For values like creation and modification timestamps, and author names.
- Custom Variables: Defined in either the global
conf
file or file-specificconf
files.
- Configuration Management: The script uses a global conf file to define global settings, such as (
-
Version Control:
- Git metadata is integrated into every page, including:
- Creation and Modification Timestamps: Automatically extracted from Git commit history.
- Page-Specific Commit History: A chronological list of all commits affecting a page, complete with commit messages, author names, and direct links to the GitHub repository.
- Git metadata is integrated into every page, including:
-
Markdown Injection:
- Converts Markdown files to HTML using
cmark-gfm
and injects the output into specified placeholders within HTML templates. - Enables the combination of simple Markdown content with HTML.
- Converts Markdown files to HTML using
-
Support for Modular Files:
- Modular content can be split into multiple files (e.g.,
0.md
,0.html
) and processed sequentially. - Markdown files are converted to HTML using
cmark-gfm
, and prebuilt HTML files are appended directly, allowing for highly customizable page structures.
- Modular content can be split into multiple files (e.g.,
-
Automatic Index and RSS Generation:
- Automatically links generated pages in an
index.html
file. - Optionally adds pages to an RSS feed, complete with titles, timestamps, and descriptions.
- Automatically links generated pages in an
- POSIX Utilities:
printf
,tr
,cut
,tail
head
: Text processing.
- cmark-gfm: Converts Markdown files into HTML.
- git: Version control system for extracting commit metadata.
- shfmt: Formats shell scripts for consistent code style.
- shellcheck: Lints shell scripts to detect errors and enforce best practices.
- pre-commit: Manages and runs hooks in Git repositories, ensuring code quality.
- prettier: Formats HTML files for consistent and readable output.
- stylelint: Lints CSS and enforces consistent styling in stylesheets.
- Ensure all dependencies are installed and accessible in your system's
PATH
. - Make the script executable:
chmod +x ./gen
- Run the script
./gen
- Unified logging.
- Parallelism maybe?
- Cache git metadata instead of invoking
git log
multiple times.