Skip to content

Connect a Git repository ​

The Git connector (git-markdown) reads Foliwake Markdown pages and their images from one branch of a GitHub or GitLab repository. Each sync reads one commit: the commit the branch points to when the sync starts.

The connector is on by default. foliwake source plugins lists it as Git repository (Markdown).

This guide uses a site called my-site and a repository https://github.com/example/my-site-content, published under /docs.

What it reads ​

  • Pages: every .md file in the configured folder and below. The files use the same Markdown and front matter as local pages. Each file needs an id: line in its front matter: the id is the page's stable identity. A file without a valid id is an error; it is never dropped silently.
  • Images: JPEG, PNG, GIF, WebP and AVIF files that a page references with a relative path.
  • Not read: other file types, and any path where a file or folder name below the configured folder starts with .. A page that references such an image is refused.
  • Never fetched or followed: submodules, symbolic links and Git LFS files. An image inside a submodule, behind a symbolic link or stored with LFS is an error.

Foliwake does not run git or clone the repository. It reads the branch over HTTPS, lists the files through the provider's API and downloads only the Markdown files and images. Every downloaded file is checked against its Git object ID.

Supported hosts ​

Hostprovider
github.comauto (default) or github
gitlab.comauto (default) or gitlab
A self-managed GitLabgitlab

GitHub Enterprise Server and other Git hosts are not supported. Only https:// addresses are accepted; SSH addresses and SSH deploy keys are not supported.

1. Create an access token ​

A public repository needs no token. For a private repository, create a read-only token:

  • GitHub: a fine-grained personal access token for this repository, with Contents: Read-only.
  • GitLab: a personal, project or group access token with the scopes read_api and read_repository.

GitLab deploy tokens do not work: Foliwake reads files through the GitLab REST API, which does not accept deploy tokens.

2. Give the token to the server ​

The site configuration names an environment variable; the server reads the token from it. Choose a name such as MY_SITE_GIT_TOKEN. It must be upper case, must not start with FOLIWAKE_, and must not be a system variable such as PATH or start with GIT_, SSH_ or NODE_.

On a server installed with foliwake docker, add a line to the instance's .env file (~/.config/foliwake/docker/<name>/.env), above the block that foliwake docker manages:

sh
MY_SITE_GIT_TOKEN=github_pat_…

Then run foliwake docker update to recreate the container with it. On other installations, set the variable in the environment of the process that runs syncs. The token is sent only to the repository's host.

3. Add the source ​

Add the source in the dashboard (Sources › Add a source, then choose Git repository (Markdown)), or with foliwake site edit --site my-site:

json
{
  "id": "docs",
  "plugin": "git-markdown",
  "owns": ["/docs"],
  "settings": {
    "repository": "https://github.com/example/my-site-content",
    "branch": "main",
    "subfolder": "pages"
  },
  "credentials": { "token": "MY_SITE_GIT_TOKEN" }
}
SettingMeaning
repositoryThe https:// address of the repository. No user name, token, query or # in it. GitHub: https://github.com/<owner>/<repo>. GitLab: https://<host>/<namespace>/<project>. Required.
branchThe branch to read, such as main. It is resolved to one commit per sync. It is separate from the branch of the frontend code. Required.
subfolderThe folder that holds the pages. Empty means the repository root.
providerauto (default), github or gitlab. Set gitlab for a self-managed GitLab.
usernameOptional user name sent with the token. Defaults: x-access-token (GitHub), oauth2 (GitLab).

Leave out credentials for a public repository.

Only a branch can be read. A tag or a fixed commit cannot be configured.

For a self-managed GitLab, use the final address of the project. Foliwake does not follow redirects there.

In the dashboard, open the source and use Check connection before the first sync.

Page paths ​

Each file says where it is published with a path: line in its front matter. To derive paths from the folder layout instead, add mappings rules to the source. They work the same as for Drive; see map folders to page paths. Paths in the rules are relative to subfolder. Check rules with foliwake source mappings check --source docs.

With mapping rules, a page's id still comes from its front matter.

Sync, preview and publish ​

A sync reads the branch into a private snapshot. Nothing changes on the preview or live site until you preview and publish.

  • Dashboard: Sources › Update source preview syncs the source and updates its pages in the preview. Review them, then publish from Pages.
  • CLI: sync with foliwake source sync --site my-site --source docs, then preview and publish.

Foliwake keeps the files it has downloaded. A sync of an unchanged branch downloads nothing, and after a new commit it usually downloads only the files that changed. Pushing to the branch does not start a sync; run one when you want the changes.

Images from a Google Drive folder ​

Lesson text can live in Git while its pictures live in a Google Drive folder: authors and illustrators keep working in Drive, and nobody commits binary files. Add driveImages to the source:

json
{
  "id": "lessons",
  "plugin": "git-markdown",
  "owns": ["/lessons"],
  "settings": {
    "repository": "https://github.com/example/lessons",
    "branch": "main",
    "subfolder": "lessons",
    "driveImages": { "auth": "service-account", "folderId": "<Drive folder ID>", "prefix": "art" }
  },
  "credentials": { "token": "LESSONS_GIT_TOKEN", "serviceAccountKey": "DRIVE_SA_KEY" }
}
  • Pages reference the pictures with ordinary relative paths, for example ![Can](../art/ge/watering/can.png). Every image whose path, relative to subfolder, starts with the prefix (default art) is read from the Drive folder by the rest of the path: art/ge/watering/can.png is ge/watering/can.png in the folder. Every other image still comes from the commit.
  • Share the folder with the service account (Viewer), or use "auth": "oauth-refresh-token" with the oauthClientId, oauthClientSecret and oauthRefreshToken credentials, as for a Google Drive folder. The scope is drive.readonly; Foliwake never writes to Drive.
  • Each download is checked against Drive's checksum. A picture that is still being saved is downloaded again (three attempts, four seconds apart); if it never matches, the sync stops with SOURCE_CHANGED and can simply be run again. A missing picture is CONTENT_IMAGE_NOT_FOUND at the page and line that use it. Names are case-sensitive; shortcuts, Google Docs or Drawings files and two items with one name are refused.
  • The pictures go through the same image pipeline as Git images and are published as /media/<hash> files. A sync pins their bytes in the snapshot and records which Drive file and checksum each page used, so a publication delivers exactly what the preview showed, even when a picture changes in Drive afterwards.
  • A sync of an unchanged branch and folder downloads nothing. After a new commit, pictures that did not change in Drive are taken from the previous snapshot.
  • A change in Drive alone does not start a sync. Run foliwake source sync (or Update source preview) after replacing pictures, or schedule syncs.
  • Files committed to Git below the prefix are ignored: the sync log warns about them, and a page that uses one gets a warning. Add the folder to .gitignore.
  • The Drive folder is not part of the source's identity: pointing folderId at another folder is allowed; the next sync reads every page and downloads every picture.

Art keys: stable picture names ​

A relative path such as ![Can](../../../../art/ge/watering/hose.png) breaks when a lesson folder moves or the art folder is reorganised. Reference a picture by its meaning instead:

md
![A watering can beside a garden bed.](art:watering/can-near-bed)

A key has no country and no extension, so every country can use the same picture. Keys are listed in art manifests (format foliwake-art/1), each with a default picture and optional per-country overrides for pictures whose content differs by country (label designs, markings, text):

json
{
  "schema": "foliwake-art/1",
  "art": {
    "art:watering/can-near-bed": {
      "default": { "drive": "<Drive file ID>", "sha256": "<checksum>", "type": "png" },
      "am": { "drive": "<Drive file ID>" }
    }
  }
}
  • Where the manifests live. The shared library is art-library.json at the root of the Drive art folder (driveImages.library names another file): every source that uses the same art folder shares it, one repository per country or one repository with several countries, without copying it. A repository may add keys or override variants in its own art-manifest.json in the source folder (driveImages.manifest); for each key and variant its entry wins. Both files are optional.
  • Resolution. A picture is found by its Drive file ID, so moving or renaming it in Drive, or moving a lesson in Git, changes nothing. A page uses its country's variant (its country field, from the source's mappings or the front matter), else default. A key in no manifest stops the sync with CONTENT_IMAGE_NOT_FOUND at the page and line. With sha256 (and type) the entry pins the picture: the Drive file must still have those bytes (CONTENT_ART_MISMATCH otherwise; update the manifest after replacing the picture). Without them, the current Drive file is used and its checksum is recorded with the snapshot.
  • Only pictures in the art folder. An entry's Drive file must lie inside the Drive art folder (folderId), at any depth of subfolders; this applies to both manifests, pinned or not. The source's credentials may read other folders (another site's art, drafts), and a manifest in Git must not be able to publish them. An entry pointing outside is refused before any byte is downloaded, like a missing picture: CONTENT_IMAGE_NOT_FOUND ("… is not inside the Drive art folder") for the pages that use the key, and foliwake art pull skips the key. Move the picture into the art folder, or correct the ID. The check runs only for pictures a sync downloads; a sync that downloads nothing makes no extra request.
  • Relative paths keep working; both can be mixed. The folder _art/ in the source is reserved for keys: a relative path into it is refused, and files committed there are ignored with a warning.

Pictures on your computer ​

foliwake dev, foliwake page check and Markdown editors read the pictures as files. Copy the Drive folder into your working copy with:

sh
cd lessons            # the source's subfolder in your clone
foliwake art pull --source lessons   # or: --root <the source folder of your clone>

It uses the source's settings and credentials from your project configuration (set the credential variables, for example DRIVE_SA_KEY, in your shell) and writes art/ (pictures referenced by path) and _art/<variant>/<key>.<ext> (every variant of every art key; --country ge keeps only the default pictures and that country's overrides), each with a small record, .foliwake-art.json. foliwake dev and page check resolve art: keys from _art/: a page gets its country's variant when its country field is known locally (front matter, or the mappings of the local source), else the default. A second run downloads only pictures that changed in Drive. It removes a picture that was deleted in Drive only when it wrote it and the file is unchanged on disk (a picture that was already there before the first run is never removed), keeps pictures you changed locally, and never writes outside the target folder. Use --to <folder> for another location. A symbolic link to a Drive for desktop folder does not work: images outside the content folder are refused.

Limits ​

LimitValue
Pages in one sync5,000
Size of one Markdown file1 MiB
Size of one image20 MiB
Entries in the repository tree200,000

GitHub and GitLab also limit API requests per token. When a provider rate-limits a sync, it reports SOURCE_RATE_LIMITED; wait and sync again.

Changing the repository ​

The repository address and subfolder are the source's identity. Changing either one, including only the upper or lower case of the address, points the source at a different upstream. Syncing then stops with SOURCE_BINDING_CHANGED, while published pages keep working. Create a new source instead. Changing branch is allowed.

Moving from a local folder ​

A site that published pages from a local folder can move them to a Git source. The new source takes over those pages only after you accept it:

sh
foliwake source adopt-pages docs --site my-site

Until then its syncs stop with SOURCE_OWNERSHIP_UNACCEPTED.