grubby: static site generator for git repos written in Ruby
grubby: static site generator for git repos written in Ruby
grubby:用 Ruby 编写的 Git 仓库静态网站生成器
grubby is a static site generator for Git repos written in Ruby. It is forked from and heavily inspired by RepoRat. grubby 是一个用 Ruby 编写的 Git 仓库静态网站生成器。它衍生自 RepoRat,并深受其启发。
Requirements
要求
- Git
- Ruby 3.0+
- Kramdown
Configuration
配置
Grubby is fairly opinionated out of the box. It’s meant to be used as-is without much need for tinkering. Kramdown is the default Markdown parser, which you are free to swap out but I can’t guarantee things will be bug-free! It is also assumed that all of your bare git repos end with the .git extension. The core repo index generation will not work properly without this!
Grubby 开箱即用,具有相当明确的预设风格。它旨在按原样使用,无需过多折腾。Kramdown 是默认的 Markdown 解析器,你可以自由更换,但我无法保证更换后不会出现 Bug!此外,系统默认你所有的裸 Git 仓库都以 .git 扩展名结尾。否则,核心仓库索引生成功能将无法正常工作!
All you should ever touch is the _config.yml file for setting your core domain and paths. If you wish to change the CSS, navigation links or footer content, then edit the style.css, _header.html, and _footer.html accordingly. Feel free to experiment! By default, the core “repo index” is created at the root of the main directory and is named index.html. You can change this file output name inside the _config.yml as well.
你唯一需要修改的就是 _config.yml 文件,用于设置核心域名和路径。如果你想更改 CSS、导航链接或页脚内容,请相应地编辑 style.css、_header.html 和 _footer.html。欢迎随意尝试!默认情况下,核心“仓库索引”会在主目录的根目录下创建,并命名为 index.html。你也可以在 _config.yml 中更改此输出文件名。
Usage
使用方法
This guide assumes you are using a form of “shared hosting” (in this case NearlyFreeSpeech.NET), although running things on your own VPS will be very similar. Below is based on your bare git repos being under /home/public/git.sitename.org.
本指南假设你使用的是某种“共享主机”(本例中为 NearlyFreeSpeech.NET),尽管在自己的 VPS 上运行过程也非常相似。以下内容基于你的裸 Git 仓库位于 /home/public/git.sitename.org 下的情况。
-
Clone this project into your private directory (ie.
/home/private/). -
将此项目克隆到你的私有目录中(例如
/home/private/)。 -
Now navigate to a repo inside
/home/public(ie.cd coolrepo.git). -
进入
/home/public下的某个仓库(例如cd coolrepo.git)。 -
Create a new file under hooks:
touch /hooks/post-update. -
在 hooks 下创建一个新文件:
touch /hooks/post-update。 -
Give that file proper permissions:
chmod +x /hooks/post-update. -
为该文件赋予适当的权限:
chmod +x /hooks/post-update。 -
Add the following code to that file:
-
将以下代码添加到该文件中:
#!/bin/sh
unset GIT_DIR
# Needed for cloning over plain HTTP
git update-server-info
# Rebuild the static site from a temporary checkout
repo_name=$(basename "$PWD" .git)
temporary_dir=$(mktemp -d)
git clone --quiet "$PWD" "$temporary_dir/$repo_name"
cp "$PWD/description" "$temporary_dir/$repo_name/.git/description"
(cd "$temporary_dir/$repo_name" && ruby /home/private/grubby/grubby.rb)
rm -rf "$temporary_dir"
Now you can take it for a test drive! Simply run: ./hooks/post-update. Your individual repo website will be generated at /home/public/git.sitename.org/coolrepo, along with an updated repo index (index.html by default) at the root /home/public/git.sitename.org/. You can expand on this by instead using this call inside your hooks/post-receive file or even using a global post-update to avoid including this for each project.
现在你可以试运行一下!只需执行:./hooks/post-update。你的个人仓库网站将生成在 /home/public/git.sitename.org/coolrepo,同时在根目录 /home/public/git.sitename.org/ 下会更新仓库索引(默认为 index.html)。你可以通过在 hooks/post-receive 文件中使用此调用,甚至使用全局 post-update 来扩展此功能,从而避免为每个项目单独包含此脚本。
Caveats
注意事项
Does not create pages for individual commit changes, branches, etc. 不会为单个提交变更、分支等创建页面。