git-preview @ main

static git web frontend but with images and html previews + code truncation

README.md

  1# Originally Forked from [legit](https://github.com/icyphox/legit)
  2An opinionated take on what a static git web frontend could be. Preview you repository in a customizeable fashion for easy deployment as a stripped-down silly showcase website. 
  3
  4example: https://jxc2000-b.github.io/git-preview/
  5
  6host [images](https://jxc2000-b.github.io/git-preview/blob/main/main.go/) [alongside](https://jxc2000-b.github.io/git-preview/blob/main/config.yaml/) your code, [interactive html demos](https://jxc2000-b.github.io/git-preview/blob/main/go.mod/) and truncate your code securely.
  7## Adding it to a new project
  8
  9```sh
 10cd my-app
 11mkdir preview-repos # parent folder that holds the apps you want to preview
 12git clone --bare . preview-repos/my-app # clone your app here and re-push here to publish updates
 13```
 14
 15## Create a conifg.yaml file, example config: 
 16
 17`config.yaml`
 18
 19```yaml
 20repo:
 21  scanPath: ./preview-repos
 22  readme:
 23    - readme
 24    - README.md
 25  mainBranch:
 26    - master
 27    - main
 28
 29meta: 
 30  title: my-app preview # site-wide metadata (title shown on browser tab)
 31  description: my-app description # search engines, link previews...
 32  syntaxHighlight: monokailight # OR github-dark, dracula, nord, onedark, rose-pine-moon, tokyonight-night...
 33
 34server:
 35  name: localhost
 36  host: 127.0.0.1
 37  port: 5555
 38```
 39
 40## Install git preview to your app
 41
 42```sh
 43cd my-app
 44go install github.com/jxc2000-b/git-preview@latest
 45```
 46## Create a .showcode folder and create a showcase.yaml file, example below 
 47
 48```sh
 49cd my-app/.showcase
 50```
 51
 52`showcase.yaml`
 53
 54```yaml
 55# Default preview setting
 56defaultPreview: full # can be full, truncated or none
 57
 58# Displayed on the repository landing page
 59landing:
 60  - asset: images/go_users.jpeg
 61    caption: You can add also images like this
 62
 63# Displayed when viewing specific files
 64files:
 65  "config.yaml":
 66    preview: full #individual overrides default
 67    assets:
 68      - asset: images/beluga.jpeg
 69        caption: Imagine these were important files detailing features or architecture 
 70  "main.go":
 71    preview: full
 72    assets:
 73      - asset: images/huh.jpeg
 74        caption: Imagine this were something cool about this file
 75  "showcase/showcase.go":
 76    preview: full
 77    assets: 
 78      - asset: html/interactive.html
 79        caption: You can add interactive demos too
 80        height: 64
 81
 82# Displayed on a particular commit page
 83commits:
 84  "bdb3273":
 85    - asset: images/andale.jpeg
 86      caption: Imagine this were the result introduced by this commit
 87```
 88## Commit and push your changes to your bare clone
 89
 90```sh
 91git add .showcase
 92git commit -m "Add project showcase"
 93git push preview-repos/my-app main
 94```
 95
 96## Generate your preview files
 97```sh
 98git-preview -config config.yaml
 99# browse at :5555
100git-preview -config config.yaml -export showcase/out # static build
101```
102
103## Local preview of an export
104```sh
105cd showcase/out && python3 -m http.server 5556
106```
107> [!IMPORTANT]
108> There are multiple issues that will arise when setting up github pages this way, I recommend you copy the workaround [workflow file](.github/workflows/static.yml) used in this repository verbatim for now while I ship fixes.
109
110## Example deploy with Github Pages
111```yaml
112- uses: actions/setup-go@v5
113- run: go install github.com/jxc2000-b/git-preview@latest
114- run: git-preview -config preview.yaml -export showcase/out
115- run: npx wrangler pages deploy showcase/out --project-name=<name>
116```
117
118Much thanks to the original developers @icyphox