Skip to content

GitHub

If your site is built from Markdown files in a GitHub repository, Unspar can add each finished article there as a new file. Your site's build then turns it into a page.

All docs pages

Many blogs are built with a static site generator like Astro, Hugo, or Next.js. The posts live as Markdown files in a Git repository, and pushing to the repository rebuilds the site. A GitHub outlet fits this setup. An outlet is where Unspar publishes finished articles. Outlets and publishing explains outlets in general.

When you publish an article to a GitHub outlet, Unspar adds one new file to the folder you chose, like src/content/blog/restore-one-table.md. It commits the file straight to your branch. If your host rebuilds the site on every push, the article goes live once that build finishes. Unspar doesn’t start the build itself. In Unspar, the article counts as published as soon as the file is in the repository.

Create a token on GitHub

Unspar needs a key that can write to your repository. On GitHub, this is a fine-grained token. You decide which repository it can reach and what it can do there.

  1. On GitHub, open Settings from your profile picture, then Developer settings.
  2. Open Personal access tokens, then Fine-grained tokens, and choose Generate new token.
  3. Name it “Unspar” and pick an Expiration.
  4. Under Resource owner, pick the account or organization that owns the repository.
  5. Under Repository access, choose Only select repositories and pick your site’s repository.
  6. Under the permissions, give Contents read and write access.
  7. Choose Generate token and copy it. GitHub shows it only once.

If the repository belongs to an organization, the organization may have to approve the token first. The token stops working on its expiration date. When that happens, publishing fails with “GitHub rejected the request (HTTP 401).” Make a new token, then go to Outlets, click the outlet’s name, paste the token into Fine-grained token, and choose Save. After that, publish the article again.

Connect the repository

  1. Open Outlets and choose New outlet.
  2. On the Assistant tab, choose the GitHub card.
  3. Under Repository owner, enter the user or organization, like example-org.
  4. Under Repository name, enter the repository, like website.
  5. Under Branch, enter the branch your site builds from, like main. It has to exist already.
  6. Under Content directory, enter the folder for the posts, like src/content/blog. Leave it empty for the top level of the repository.
  7. Paste the token into Fine-grained token.
  8. Give the outlet a Name, choose Test connection and then Create outlet.

The test only reads the repository and the branch. It doesn’t commit anything, so it can’t confirm that Unspar can write there.

Unspar commits directly and doesn’t open a pull request. If your branch only accepts pull requests, publishing fails. In that case, or if you want to review each article first, point the outlet at a separate branch like articles. From there, you can open the pull request yourself.

The GitHub outlet works with repositories on GitHub.com. For GitLab or another Git host, use a webhook or save the file with the CLI, as described below.

GitHub outlet form with Repository owner example-org, Repository name website, Branch main, Content directory src/content/blog and a fine-grained token
Enter the repository, the branch and the folder for your posts, and paste the token.

What does the file look like?

The file name is the article’s slug with .md at the end. The slug is the short form of the title used in URLs. The file starts with front matter, which is the block between the two --- lines that holds fields your site reads. The article follows in Markdown.

---
title: "How to restore one table from a pg_dump backup"
description: "Restore a single table from a full pg_dump file without touching the rest of the database."
date: "2026-11-24T14:12:09+00:00"
slug: "restore-one-table"
tags: ["postgres", "backups"]
image: "https://app.unspar.com/content-media/..."
unspar_id: "01JX9Q3M4N5P6R7S8T9V0W1X2Y"
draft: false
---

A full pg_dump file holds every table, but you often need only one ...

The fields are always the same, and you can’t change them in Unspar. description is the meta description Unspar wrote. tags and image are left out when the article has none. draft is always false.

date is when Unspar finished the article, rather than when you published it. If your site sorts posts by date and the day matters, change it in the file.

Images stay on Unspar’s server. image holds the URL of the featured image, and images in the text are normal Markdown image links. If you delete the article in Unspar, those images stop working.

Unspar never overwrites a file. If a file with the same name already exists, publishing fails with “A file already exists at” followed by the path. Once the file is created, Unspar doesn’t change or delete it. Edit it on GitHub if something needs fixing.

Read the fields in your site

Hugo reads the front matter as it is. Set the Content directory to a section like content/posts. Your theme decides where it shows image.

Astro reads the posts as a content collection. Point the collection at your Content directory and list the fields in its schema. This works in Astro 5 and newer:

// src/content.config.ts
import { defineCollection } from "astro:content";
import { glob } from "astro/loaders";
import { z } from "astro/zod";

const blog = defineCollection({
  loader: glob({ base: "./src/content/blog", pattern: "**/*.md" }),
  schema: z.object({
    title: z.string(),
    description: z.string(),
    date: z.coerce.date(),
    slug: z.string(),
    tags: z.array(z.string()).optional(),
    image: z.string().optional(),
    unspar_id: z.string(),
    draft: z.boolean(),
  }),
});

export const collections = { blog };

Astro’s blog template calls the fields pubDate and heroImage. Rename them to date and image in the schema and the templates. If you show the image with Astro’s <Image> component, add app.unspar.com to image.domains in your Astro config.

Next.js has no fixed folder for posts. Your own code reads them, for example with the gray-matter library. Set the Content directory to that folder. If you use next/image, add app.unspar.com to images.remotePatterns.

Commit the file yourself

If you’d rather commit by hand, the unspar CLI saves an article as a Markdown file into your repository:

unspar articles content <article-id> --with-images --output content/posts/restore-one-table.md

The folder has to exist, and the CLI never overwrites a file. This file has no front matter, so add the fields your site expects before you commit it.

For AI agents

An agent can create a GitHub outlet from the terminal with the api command. Put the token in a protected file and pass --secret-field api_key, so the token never shows in the output. Delete the file afterwards. An agent can also save an article as Markdown into the repository and commit it like any other file. The folder for --output has to exist, and the CLI never overwrites a file. Publishing asks for confirmation unless you pass --force. Use --force only after a person has read the article and said yes.

unspar api post /outlets --body-file github-outlet.json --secret-field api_key
unspar outlets list
unspar api post /outlets/<outlet-id>/test
unspar articles publish <article-id> --outlet <outlet-id>
unspar api patch /outlets/<outlet-id> --body-file outlet-settings.json --secret-field api_key
unspar articles create --project <project-id> --brief "How to restore one table from a pg_dump backup" --force --wait
unspar articles content <article-id> --with-images --output content/posts/restore-one-table.md
unspar articles publish <article-id> --outlet <outlet-id> --force

unspar <command> --help lists each command's flags and output options. Install and login: the CLI docs.

Last updated 25 November 2026. This page as Markdown: github.md

Try Unspar for free

Create a project, give it a topic and read the article before anything goes live.