|
| 1 | +{{ define "main" }} |
| 2 | +<div class="mb-3"> |
| 3 | + <h1 class="text-3xl font-semibold tracking-tight mb-2">Packages</h1> |
| 4 | + <p class="text-[#a89984]">Search the custom XBPS repository.</p> |
| 5 | + <div class="flex items-center gap-2 mt-3"> |
| 6 | + <a |
| 7 | + href="https://git.ch-naseem.com/noid-linux/xbps-repo" |
| 8 | + target="_blank" |
| 9 | + rel="noopener" |
| 10 | + class="flex items-center gap-1.5 text-xs font-mono bg-[#282828] border border-[#504945] hover:border-[#d79921]/50 text-[#a89984] px-3 py-1.5 rounded-md transition-colors" |
| 11 | + > |
| 12 | + <img |
| 13 | + src="https://cdn.simpleicons.org/forgejo/a89984" |
| 14 | + width="12" |
| 15 | + height="12" |
| 16 | + alt="" |
| 17 | + /> |
| 18 | + Forgejo |
| 19 | + </a> |
| 20 | + <a |
| 21 | + href="https://github.com/noid-linux/xbps-repo" |
| 22 | + target="_blank" |
| 23 | + rel="noopener" |
| 24 | + class="flex items-center gap-1.5 text-xs font-mono bg-[#282828] border border-[#504945] hover:border-[#d79921]/50 text-[#a89984] px-3 py-1.5 rounded-md transition-colors" |
| 25 | + > |
| 26 | + <img |
| 27 | + src="https://cdn.simpleicons.org/github/a89984" |
| 28 | + width="12" |
| 29 | + height="12" |
| 30 | + alt="" |
| 31 | + /> |
| 32 | + GitHub |
| 33 | + </a> |
| 34 | + </div> |
| 35 | +</div> |
| 36 | + |
| 37 | +<div class="relative mb-3"> |
| 38 | + <input |
| 39 | + id="pkg-search" |
| 40 | + type="text" |
| 41 | + placeholder="Search packages..." |
| 42 | + autocomplete="off" |
| 43 | + autofocus="on" |
| 44 | + class="w-full bg-[#282828] border border-3 border-[#504945] focus:border-[#d79921] outline-none rounded-md px-4 py-2.5 text-[#ebdbb2] placeholder-[#a89984] font-mono text-sm transition-colors" |
| 45 | + /> |
| 46 | +</div> |
| 47 | + |
| 48 | +<div class="bg-[#282828] border border-[#504945] rounded-md overflow-hidden"> |
| 49 | + <table class="w-full text-sm table-fixed"> |
| 50 | + <thead> |
| 51 | + <tr class="border-b border-[#504945]"> |
| 52 | + <th class="text-left px-4 py-3 text-[#d79921] font-semibold w-2/3"> |
| 53 | + Package |
| 54 | + </th> |
| 55 | + <th class="text-left px-4 py-3 text-[#d79921] font-semibold w-1/3"> |
| 56 | + Version |
| 57 | + </th> |
| 58 | + </tr> |
| 59 | + </thead> |
| 60 | + <tbody id="pkg-table"></tbody> |
| 61 | + </table> |
| 62 | + <p |
| 63 | + id="pkg-empty" |
| 64 | + class="hidden text-center text-[#a89984] font-mono text-sm py-8" |
| 65 | + > |
| 66 | + // no results |
| 67 | + </p> |
| 68 | + <div |
| 69 | + id="pkg-pagination" |
| 70 | + class="hidden items-center justify-between px-4 py-3 border-t border-[#504945]" |
| 71 | + > |
| 72 | + <span id="pkg-info" class="text-[#a89984] font-mono text-xs"></span> |
| 73 | + <div class="flex items-center gap-1"> |
| 74 | + <button |
| 75 | + id="pkg-prev" |
| 76 | + class="px-3 py-1.5 rounded-md text-xs font-mono text-[#a89984] hover:text-[#ebdbb2] hover:bg-[#3c3836] disabled:opacity-30 disabled:cursor-not-allowed transition-colors" |
| 77 | + > |
| 78 | + ← prev |
| 79 | + </button> |
| 80 | + <span id="pkg-pages" class="flex gap-1"></span> |
| 81 | + <button |
| 82 | + id="pkg-next" |
| 83 | + class="px-3 py-1.5 rounded-md text-xs font-mono text-[#a89984] hover:text-[#ebdbb2] hover:bg-[#3c3836] disabled:opacity-30 disabled:cursor-not-allowed transition-colors" |
| 84 | + > |
| 85 | + next → |
| 86 | + </button> |
| 87 | + </div> |
| 88 | + </div> |
| 89 | +</div> |
| 90 | +<div class="bg-[#282828] border border-[#504945] rounded-md p-5 mt-3 text-sm"> |
| 91 | + <p class="font-mono text-xs text-[#d79921] mb-3">// install</p> |
| 92 | + <p class="text-[#a89984] mb-2">Add the repository:</p> |
| 93 | + <pre |
| 94 | + class="bg-[#1d2021] border border-[#504945] rounded-md px-4 py-3 font-mono text-xs text-[#ebdbb2] overflow-x-auto mb-4" |
| 95 | + ><code>echo "repository=https://github.com/noid-linux/xbps-repo/releases/latest/download" | sudo tee /etc/xbps.d/noid-xbps-repo.conf</code></pre> |
| 96 | + <p class="text-[#a89984] mb-2">Then install packages:</p> |
| 97 | + <pre |
| 98 | + class="bg-[#1d2021] border border-[#504945] rounded-md px-4 py-3 font-mono text-xs text-[#ebdbb2] overflow-x-auto" |
| 99 | + ><code>sudo xbps-install -Su |
| 100 | +sudo xbps-install brave librewolf vscodium obsidian intel-media-driver-nonfree</code></pre> |
| 101 | +</div> |
| 102 | +<script src="https://cdn.jsdelivr.net/npm/fuse.js/dist/fuse.min.js"></script> |
| 103 | +<script> |
| 104 | + (() => { |
| 105 | + const RAW_URL = |
| 106 | + "https://raw.githubusercontent.com/noid-linux/xbps-repo/main/PACKAGES.md"; |
| 107 | + const TEMPLATE_BASE = |
| 108 | + "https://git.ch-naseem.com/noid-linux/xbps-repo/src/branch/main/srcpkgs"; |
| 109 | + const PAGE_SIZE = 13; |
| 110 | + const WINDOW_SIZE = 4; |
| 111 | + |
| 112 | + const el = (id) => document.getElementById(id); |
| 113 | + const tbody = el("pkg-table"); |
| 114 | + const empty = el("pkg-empty"); |
| 115 | + const pagination = el("pkg-pagination"); |
| 116 | + const info = el("pkg-info"); |
| 117 | + const pages = el("pkg-pages"); |
| 118 | + const prevBtn = el("pkg-prev"); |
| 119 | + const nextBtn = el("pkg-next"); |
| 120 | + const search = el("pkg-search"); |
| 121 | + |
| 122 | + let results = []; |
| 123 | + let currentPage = 1; |
| 124 | + let fuse; |
| 125 | + |
| 126 | + function parseMd(md) { |
| 127 | + return md |
| 128 | + .split("\n") |
| 129 | + .filter( |
| 130 | + (l) => |
| 131 | + l.startsWith("|") && !l.includes("---") && !l.includes("Package"), |
| 132 | + ) |
| 133 | + .map((l) => { |
| 134 | + const [, name, version] = l.split("|").map((s) => s.trim()); |
| 135 | + return { name, version }; |
| 136 | + }) |
| 137 | + .filter((p) => p.name); |
| 138 | + } |
| 139 | + |
| 140 | + function pageWindow(current, total) { |
| 141 | + let start = Math.max(1, current - 1); |
| 142 | + let end = start + WINDOW_SIZE - 1; |
| 143 | + if (end > total) { |
| 144 | + end = total; |
| 145 | + start = Math.max(1, end - WINDOW_SIZE + 1); |
| 146 | + } |
| 147 | + return Array.from({ length: end - start + 1 }, (_, i) => start + i); |
| 148 | + } |
| 149 | + |
| 150 | + function render() { |
| 151 | + const total = Math.ceil(results.length / PAGE_SIZE); |
| 152 | + const start = (currentPage - 1) * PAGE_SIZE; |
| 153 | + const slice = results.slice(start, start + PAGE_SIZE); |
| 154 | + |
| 155 | + const hasResults = results.length > 0; |
| 156 | + empty.classList.toggle("hidden", hasResults); |
| 157 | + pagination.classList.toggle("hidden", !hasResults); |
| 158 | + pagination.classList.toggle("flex", hasResults); |
| 159 | + |
| 160 | + tbody.innerHTML = slice |
| 161 | + .map( |
| 162 | + (p) => ` |
| 163 | + <tr data-href="${TEMPLATE_BASE}/${p.name}/template" |
| 164 | + class="border-b border-[#3c3836] last:border-0 hover:bg-[#3c3836]/40 cursor-pointer transition-colors" |
| 165 | + title="View template for ${p.name}"> |
| 166 | + <td class="px-4 py-3 font-mono text-[#ebdbb2]">${p.name}</td> |
| 167 | + <td class="px-4 py-3 font-mono text-[#a89984]">${p.version}</td> |
| 168 | + </tr>`, |
| 169 | + ) |
| 170 | + .join(""); |
| 171 | + |
| 172 | + if (!hasResults) return; |
| 173 | + |
| 174 | + info.textContent = `${start + 1}–${Math.min(start + PAGE_SIZE, results.length)} of ${results.length}`; |
| 175 | + prevBtn.disabled = currentPage === 1; |
| 176 | + nextBtn.disabled = currentPage === total; |
| 177 | + |
| 178 | + pages.innerHTML = pageWindow(currentPage, total) |
| 179 | + .map( |
| 180 | + (n) => ` |
| 181 | + <button data-page="${n}" |
| 182 | + class="w-7 h-7 rounded-md text-xs font-mono transition-colors ${ |
| 183 | + n === currentPage |
| 184 | + ? "bg-[#d79921] text-[#1d2021] font-bold" |
| 185 | + : "text-[#a89984] hover:text-[#ebdbb2] hover:bg-[#3c3836]" |
| 186 | + }"> |
| 187 | + ${n} |
| 188 | + </button>`, |
| 189 | + ) |
| 190 | + .join(""); |
| 191 | + } |
| 192 | + |
| 193 | + tbody.addEventListener("click", (e) => { |
| 194 | + const row = e.target.closest("tr[data-href]"); |
| 195 | + if (row) window.open(row.dataset.href, "_blank"); |
| 196 | + }); |
| 197 | + |
| 198 | + pages.addEventListener("click", (e) => { |
| 199 | + const btn = e.target.closest("button[data-page]"); |
| 200 | + if (btn) { |
| 201 | + currentPage = +btn.dataset.page; |
| 202 | + render(); |
| 203 | + } |
| 204 | + }); |
| 205 | + |
| 206 | + prevBtn.addEventListener("click", () => { |
| 207 | + if (currentPage > 1) { |
| 208 | + currentPage--; |
| 209 | + render(); |
| 210 | + } |
| 211 | + }); |
| 212 | + |
| 213 | + nextBtn.addEventListener("click", () => { |
| 214 | + const total = Math.ceil(results.length / PAGE_SIZE); |
| 215 | + if (currentPage < total) { |
| 216 | + currentPage++; |
| 217 | + render(); |
| 218 | + } |
| 219 | + }); |
| 220 | + |
| 221 | + search.addEventListener("input", (e) => { |
| 222 | + currentPage = 1; |
| 223 | + const q = e.target.value.trim(); |
| 224 | + results = q ? fuse.search(q).map((r) => r.item) : fuse._docs; |
| 225 | + render(); |
| 226 | + }); |
| 227 | + |
| 228 | + fetch(RAW_URL) |
| 229 | + .then((r) => r.text()) |
| 230 | + .then((md) => { |
| 231 | + const packages = parseMd(md); |
| 232 | + fuse = new Fuse(packages, { keys: ["name"], threshold: 0.35 }); |
| 233 | + results = packages; |
| 234 | + render(); |
| 235 | + }); |
| 236 | + })(); |
| 237 | +</script> |
| 238 | +{{ end }} |
0 commit comments