repo.njk

---
pagination:
  data: branches
  size: 1
  alias: branch
permalink: "repos/{{branch.repoName | slugify}}/branches/{{branch.branchName}}/"
navTab: landing
---
<div class="row">
  <div class="col-md-8 col-sm-12 order-md-1 order-sm-2">
    {{ branch.repoName | getReadMe(branch.branchName) | renderContent("md") | safe }}
  </div>
  <div class="col-md-4 col-sm-12 order-md-2 order-sm-1">
    <div class="row">
      <div class="col">
        <div class="row mb-2">
          <div class="col">
            <h2 class="fs-6 my-0">Clone {{branch.repoName}} / {{branch.branchName}}</h2>
          </div>
        </div>
        <div class="row">
          <div class="col">
            <div class="input-group mb-4 d-flex flex-nowrap">
              <span id="clone-command" class="clone overflow-hidden input-group-text">
                {% set url = [darcsConfig.baseUrl, "/repos/", branch.repoName | slugify, "/branches/", branch.branchName | slugify] | join | url %}
                darcs clone {{ url }}
              </span>
              <button class="btn btn-primary" id="clone-button" onclick="copyCommand()">Copy</button>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col">
        <div class="row align-items-center">
          <div class="col-auto">
            <h2 class="fs-6 my-0">Recent patches in {{branch.branchName}}</h2>
          </div>
          <div class="col-auto">
            <a href="/repos/{{ branch.repoName | slugify }}/branches/{{ branch.branchName | slugify }}/patches.xml" class="initialism">RSS<i class="bi bi-rss-fill ms-2" style="color: orange;"></i></a>
          </div>
        </div>
        {% for patch in repos[branch.repoName][branch.branchName].patches | batch(3) | first %}
        <div class="card mt-2 mb-4">
          <div class="card-body">
            <a href="/repos/{{branch.repoName | slugify}}/branches/{{branch.branchName | slugify}}/patches/{{patch.hash}}" class="text-primary d-inline-block card-title text-decoration-none fs-5">{{patch.name}}</a>
            <p class="card-subtitle fs-6 mb-2 text-body-secondary">{{patch.date}}</p>
            <p class="card-subtitle fs-6 mb-2 text-body-secondary">{{patch.author}}</p>
            <p class="card-text">{{patch.description | truncate(150)}}</p>
          </div>
          <div class="card-footer">
            <span class="card-link font-monospace" data-hash="{{patch.hash}}" id="copy-pull-{{loop.index}}">{{patch.hash | truncate(8, true, "")}}</span><button id="pull-button-{{loop.index}}" onclick="copyPull({{loop.index}})" class="btn btn-sm btn-outline-primary ms-2"><i class="bi-copy bi me-1"></i>Pull</button>
          </div>
        </div>
        {% endfor %}
      </div>
    </div>
  </div>
</div>

<script>
  const copyCommand = () => {
    const text = document.getElementById("clone-command").innerText
    const button = document.getElementById("clone-button")
    navigator.clipboard.writeText(text).then(() => {
      button.innerText = "Copied"
    })
  }

  const copyPull = (index) => {
    const spanElem = document.getElementById(`copy-pull-${index}`)
    const hash = spanElem.attributes["data-hash"].value
    const button = document.getElementById(`pull-button-${index}`)
    navigator.clipboard.writeText(`darcs pull {{url}} -h ${hash}`).then(() => {
      button.innerHTML = button.innerHTML.replace("Pull", "Copied")
    })

  }
</script>