Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions content/single-source-docs/module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Single-Source Documentation: One Markdown File for Your README and Website

<details>
slug: single-source-docs
published: 03/15/2026
author: Cory LaNou
seo_description: Learn how to use Hype to maintain a single Markdown source that generates both your GitHub README and website documentation, keeping them permanently in sync.
tags: tutorial, docs, workflow, hype
</details>

Every open source project has the same problem: documentation lives in too many places. Your README says one thing, your docs site says another, and the install instructions in your wiki are three versions behind. You end up maintaining the same content in multiple locations, and they inevitably drift apart.

Hype solves this by letting you write your documentation once and generate multiple outputs from a single source.

## The Problem

A typical project has documentation scattered across:

- `README.md` in the repo root
- A docs site (GitHub Pages, Netlify, etc.)
- Wiki pages
- Blog posts or tutorials

When you update an API or change an install command, you have to remember to update every copy. You won't. Nobody does.

## The Hype Approach

With Hype, you write a single `hype.md` file that includes source files, executes code, and validates everything at build time. Then you generate your README from it:

```bash
hype export -format markdown -f hype.md > README.md
```

Your README is now a build artifact, not a hand-maintained file. Change the source, regenerate, and every output stays in sync.

## A Practical Example

Let's say you're building a Go CLI tool. Your documentation needs to show:

1. How to install it
2. A code example
3. The command's help output

### Step 1: Create Your Source File

Create a `hype.md` at the root of your project:

```markdown
# My CLI Tool

A fast and simple tool for doing things.

## Installation

&#96;&#96;&#96;bash
go install github.com/you/tool@latest
&#96;&#96;&#96;
Comment on lines +55 to +57

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use literal code fences in embedded hype.md example

The hype.md example escapes backticks as &#96; inside a fenced markdown block, so readers will see/copy the entity text instead of real triple backticks when following the tutorial. In CommonMark-style renderers, entities are not decoded inside code blocks, so this produces an invalid nested fence in the copied file and the install snippet won’t render as intended in the generated README.

Useful? React with 👍 / 👎.


## Quick Example

&lt;code src="examples/hello/main.go"&gt;&lt;/code&gt;

## Usage

&lt;cmd exec="go run ./cmd/tool -h"&gt;&lt;/cmd&gt;
```

The `<code>` tag includes your actual source file. The `<cmd>` tag runs a command and captures the output. Both happen at build time.

### Step 2: Generate Your README

```bash
hype export -format markdown -f hype.md > README.md
```

The generated README contains the actual contents of `examples/hello/main.go` and the real output of `go run ./cmd/tool -h`. If either changes, the next build picks it up automatically.

### Step 3: Automate It

Add a CI step so the README regenerates on every push. The Hype repo itself does exactly this — a GitHub Actions workflow runs `hype export` and commits the updated README if it changed.

Here's a minimal workflow:

```yaml
name: Generate README
on:
push:
branches: [main]

jobs:
readme:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- run: go install github.com/gopherguides/hype/cmd/hype@latest
- run: hype export -format markdown -f hype.md > README.md
- name: Commit if changed
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add README.md
git diff --cached --quiet || git commit -m "docs: regenerate README"
git push
```

## Why This Matters

When your code example is included from a real file, the compiler validates it. When your CLI output is captured from the actual binary, it reflects the current behavior. When a build step generates your README, you can't forget to update it.

The result is documentation that is always correct because it's derived from the source of truth — your code.

## Going Further

This same pattern scales beyond READMEs:

- **Website docs**: Use the same source files to generate pages for your docs site (this is exactly how [hypemd.dev](https://hypemd.dev) works — docs are synced from the Hype repo automatically)
- **Blog posts**: Write tutorials with executable code examples that are validated every time you build
- **Training materials**: Include code snippets and exercise outputs that stay current as your codebase evolves

The key insight is simple: documentation should be a build artifact, not a source file. Write it once, generate it everywhere, and let the build system keep it honest.

## Get Started

Install Hype and try it on your own project:

```bash
brew install gopherguides/tap/hype
```

Or with Go:

```bash
go install github.com/gopherguides/hype/cmd/hype@latest
```

Create a `hype.md`, include some source files, and run `hype export -format markdown`. You'll never hand-maintain a README again.
1 change: 1 addition & 0 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<a href="/docs/" class="hover:text-emerald-400 transition-colors">Docs</a>
<a href="/" class="hover:text-emerald-400 transition-colors">Blog</a>
<a href="https://github.com/gopherguides/hype" class="hover:text-emerald-400 transition-colors">GitHub</a>
<a href="https://x.com/hype_markdown" class="hover:text-emerald-400 transition-colors">𝕏</a>
<a href="/rss.xml" class="hover:text-emerald-400 transition-colors">RSS</a>
</div>
<p>
Expand Down
1 change: 1 addition & 0 deletions layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<a href="/docs/" class="text-gray-400 hover:text-emerald-400 transition-colors">docs</a>
<a href="/" class="text-gray-400 hover:text-emerald-400 transition-colors">blog</a>
<a href="https://github.com/gopherguides/hype" class="text-gray-400 hover:text-emerald-400 transition-colors">github</a>
<a href="https://x.com/hype_markdown" class="text-gray-400 hover:text-emerald-400 transition-colors">𝕏</a>
<a href="/rss.xml" class="text-gray-400 hover:text-emerald-400 transition-colors">[rss]</a>
</div>
</nav>
Expand Down
Loading