Add a branches page, and allow the user to switch between them

Sun Apr 13 2025

Tucker McKnight

Adds a branches tab to the top nav, which shows a list of branches.

Adds a description field to each branch, which is shown on the
branches page.

Adds a select box to the top nav that allows you to change between branches.

9a8d8349120255fa78d56bc28127a10db26ed107

darcs pull https://repos.tuckerm.us/repos/eleventy-darcs/branches/main -h 9a8d8349120255fa78d56bc28127a10db26ed107
_includes/main.njk:56
Before
                  <a href="/" class="text-decoration-none">Darcs Repositories</a>{% if nav.repoName %}<span class="text-secondary mx-2">&gt;</span><a href="/repos/{{nav.repoName | slugify}}/branches/{{darcsConfig.repos[nav.repoName].defaultBranch | slugify}}" class="text-decoration-none">{{nav.repoName}}</a>{% endif %}{% if nav.branchName %}<span class="text-secondary mx-2">&gt;</span><a class="text-decoration-none" href="/repos/{{nav.repoName | slugify}}/branches/{{nav.branchName | slugify}}">{{nav.branchName}}</a>{% endif %}
After
                  <a href="/" class="text-decoration-none">Darcs Repositories</a>{% if nav.repoName %}<span class="text-secondary mx-2">&gt;</span><a href="/repos/{{nav.repoName | slugify}}/branches/{{darcsConfig.repos[nav.repoName].defaultBranch | slugify}}" class="text-decoration-none">{{nav.repoName}}</a>{% endif %}
_includes/main.njk:68
Before
            <nav class="nav-tabs mb-4">
                  <ul class="nav">
                    <li class="nav-item">
                      <a class="nav-link {% if navTab == "landing" %}active{% endif %}" href="/repos/{{nav.repoName | slugify}}/branches/{{nav.branchName}}">Landing Page</a>
                    </li>
                    <li class="nav-item">
                      <a class="nav-link {% if navTab == "files" %}active{% endif %}" href="/repos/{{nav.repoName | slugify}}/branches/{{nav.branchName}}/files">Files</a>
                    </li>
                    <li class="nav-item">
                      <a class="nav-link {% if navTab == "patches" %}active{% endif %}" href="/repos/{{nav.repoName | slugify}}/branches/{{nav.branchName}}/patches/page1">Patches</a>
                    </li>
                    </ul>
                </nav>
              
After
            <div class="row mb-4">
              <div class="col pe-0">
                <nav class="nav-tabs">
                  <ul class="nav">
                    <li class="nav-item">
                      <a class="nav-link {% if navTab == "landing" %}active{% endif %}" href="/repos/{{nav.repoName | slugify}}/branches/{{nav.branchName}}">Landing Page</a>
                    </li>
                    <li class="nav-item">
                      <a class="nav-link {% if navTab == "files" %}active{% endif %}" href="/repos/{{nav.repoName | slugify}}/branches/{{nav.branchName}}/files">Files</a>
                    </li>
                    <li class="nav-item">
                      <a class="nav-link {% if navTab == "patches" %}active{% endif %}" href="/repos/{{nav.repoName | slugify}}/branches/{{nav.branchName}}/patches/page1">Patches</a>
                    </li>
                    <li class="nav-item">
                      <a class="nav-link {% if navTab == "branches" %}active{% endif %}" href="/repos/{{nav.repoName | slugify}}/branches/{{nav.branchName | slugify}}/list">Branches</a>
                    </li>
                  </ul>
                </nav>
              </div>
              <div class="col-auto border-bottom">
                <div class="input-group input-group-sm">
                  <span class="input-group-text">Branch</span>
                  <select class="form-select" onchange="selectBranch(this)" aria-label="Repository branch selector">
                    {% for branch in branches %}
                    <option value="{{branch.repoName | slugify}},{{branch.branchName | slugify}},{{nav.path}}" {% if branch.branchName == nav.branchName %}selected{% endif %}>{{branch.branchName}}</option>
                    {% endfor %}
                  </select>
                </div>
              </div>
            </div>
_includes/main.njk:131
Before
After
      }

      const selectBranch = (e) => {
        const values = e.value.split(",")
        window.location = `/repos/${values[0]}/branches/${values[1]}/${values[2]}`
branches.11tydata.js:1
Before
After
export default {
  eleventyComputed: {
    nav: {
      repoName: (data) => {
        return data.branchInfo.repoName
      },
      branchName: (data) => {
        return data.branchInfo.branchName
      },
      path: "list",
    }
  }
}
branches.njk:1
Before
After
---
pagination:
  data: branches
  size: 1
  alias: branchInfo
permalink: "repos/{{branchInfo.repoName | slugify}}/branches/{{branchInfo.branchName | slugify}}/list/"
navTab: branches
---
<ul>
{% for branch in branches %}
  {% set description = darcsConfig.repos[branch.repoName].branches[branch.branchName].description %}
  <li><a href="/repos/{{branch.repoName | slugify}}/branches/{{branch.branchName | slugify}}">{{branch.branchName}}</a>{% if branch.branchName == branchInfo.branchName %} (current){% endif %}{% if description %} - {{ description }}{% endif %}</li>
{% endfor %}
</ul>
darcsconfig.js:5
Before
      defaultBranch: 'eleventy-darcs-main',
After
      defaultBranch: 'main',
darcsconfig.js:7
Before
        'eleventy-darcs-main': {
After
        'main': {
darcsconfig.js:11
Before
After
          description: "Main branch of this project."
        },
        'works-in-progress': {
          location: "../clone-of-eleventy-darcs/eleventy-darcs-clone/",
          description: "Ongoing dev work in this project. Patches here may be unrecorded and modified at any time.",
eleventy.config.js:39
Before
  eleventyConfig.addFilter("pagesJustForRepo", (pages, repoName) => {
    return pages.filter(page => page.repoName === repoName )
After
  eleventyConfig.addFilter("pagesJustForBranch", (pages, repoName, branchName) => {
    return pages.filter(page => page.repoName === repoName && page.branchName === branchName)
file.11tydata.js:9
Before
After
      },
      path: (data) => {
        return `files/${data.fileInfo.file}`
file.njk:9
Before
After
files.11tydata.js:9
Before
      }
After
      },
      path: "files"
files.njk:9
Before
<ul>
    {% set files = repos[branchInfo.repoName][branchInfo.branchName].files | topLevelFilesOnly %}
    {% for file in files %}
      <li><a href="/repos/{{branchInfo.repoName | slugify}}/branches/{{branchInfo.branchName}}/files/{{file}}.html">{{file}}</a></li>
    {% endfor %}
    </ul>
  
After
<div class="row">
  <div class="col">
    <ul>
    {% set files = repos[branchInfo.repoName][branchInfo.branchName].files | topLevelFilesOnly %}
    {% for file in files %}
      <li><a href="/repos/{{branchInfo.repoName | slugify}}/branches/{{branchInfo.branchName}}/files/{{file}}.html">{{file}}</a></li>
    {% endfor %}
    </ul>
  </div>
</div>
patch.11tydata.js:9
Before
After
      },
      path: (data) => {
        return `patches/${data.patchInfo.patch.hash}`
patches.11tydata.js:9
Before
      }
After
      },
      path: "patches/page1",
patches.njk:11
Before
    {% for pageObj in (paginatedPatches | pagesJustForRepo(patchPage.repoName)) %}
After
    {% for pageObj in (paginatedPatches | pagesJustForBranch(patchPage.repoName, patchPage.branchName)) %}
patches.njk:34
Before
    {% for pageObj in (paginatedPatches | pagesJustForRepo(patchPage.repoName)) %}
After
    {% for pageObj in (paginatedPatches | pagesJustForBranch(patchPage.repoName, patchPage.branchName)) %}
repo.11tydata.js:9
Before
      }
After
      },
      path: "",