https://github.com/mraerino/hugo-preview-server
Preview changes to a Hugo site live in a CMS
https://github.com/mraerino/hugo-preview-server
Last synced: 7 days ago
JSON representation
Preview changes to a Hugo site live in a CMS
- Host: GitHub
- URL: https://github.com/mraerino/hugo-preview-server
- Owner: mraerino
- License: mit
- Created: 2020-04-13T14:17:49.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2020-04-16T16:27:17.000Z (about 5 years ago)
- Last Synced: 2025-05-07T22:04:15.985Z (7 days ago)
- Language: Go
- Homepage:
- Size: 2.91 MB
- Stars: 3
- Watchers: 3
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Hugo Preview Server
**This is in an early stage:** It has only been tested with a single demo site and misses some features.
## Summary
A piece of glue code that runs Hugo for serving previews for CMS systems.
It uses a git client to get access to assets/layouts of the site and compiles pages based on content passed in via HTTP.
### DEMO
There is a demo setup at: https://hugo-preview-server.netlify.com/demo/admin/
Log in via GitHub and select any entry from the "Posts" collection to see it in action.
## Features
- Uses GitHub as a virtual filesystem to get layouts
- Renders pages on-demand, taking `path` and `data` via `POST`
- Supports partial re-renders (just like `hugo server`)
- Supports extended mode## Roadmap
- Build & package a solid integration for [NetlifyCMS](https://www.netlifycms.org/)
- Support custom source branches (only default right now)
- Provide tooling for easy usage (e.g. `npx hugo-preview-server setup:function ./functions`)
- Run as a standalone http server process (for use in docker)## Usage
There is a binary available that can be deployed to AWS Lambda or any compatible platforms like [Netlify Functions](https://www.netlify.com/products/functions/).
### Download in CI
Use this command in your build to get the latest release:
```
curl -L -s https://github.com/mraerino/hugo-preview-server/releases/latest/download/preview-lambda -o# Example for Netlify Functions
mkdir -p functions
curl -L -s https://github.com/mraerino/hugo-preview-server/releases/latest/download/preview-lambda -o functions/preview
chmod +x functions/preview
```See [this `Netlify.toml`](demo/netlify.toml) for an example.
In the future there will be tooling that will make this even easier.### Configuration
The functions needs the following environment variables:
```bash
HUGO_PREVIEW_GITHUB_REPO=owner/repo # path to the repo where your hugo site is located
HUGO_PREVIEW_GITHUB_TOKEN= # a personal or oauth token that allows read access to the repo
HUGO_PREVIEW_BASE= # optional, use when your hugo site is not based in the repo root
```## Run locally
Requirements:
- Docker
- [SAM](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)While developing, use the one of the make commands to get a binary:
- `make build` - if you are on linux
- `make in-docker` - any other systemPut your config vars into `env.json`, like this:
```
{
"PreviewFunction": {
"HUGO_PREVIEW_GITHUB_TOKEN": "",
"HUGO_PREVIEW_GITHUB_REPO": "owner/repo",
"HUGO_PREVIEW_BASE": ""
}
}
```Run this to start the local API gateway:
```bash
sam local start-api --env-vars env.json
```This is how the API request should look like:
```js
POST http://127.0.0.1:3000/render{
"path": "content/my-page.md",
"data": {
"body": "markdown body",
"title": "title frontmatter field",
"other": "frontmatter"
}
}
```## License
See [LICENSE file](LICENSE.md)