- commit
- f627ed2
- parent
- ef8b3df
- author
- Eric Bower
- date
- 2023-03-09 04:28:53 +0000 UTC
feat: sort by links preserve search query
4 files changed,
+45,
-13
+7,
-1
1@@ -91,11 +91,17 @@
2 "https://deno.land/x/path_to_regexp@v6.2.1/index.ts": "894060567837bae8fc9c5cbd4d0a05e9024672083d5883b525c031eea940e556"
3 },
4 "npm": {
5- "specifiers": { "marked": "marked@4.2.3" },
6+ "specifiers": {
7+ "marked": "marked@4.2.4"
8+ },
9 "packages": {
10 "marked@4.2.3": {
11 "integrity": "sha512-slWRdJkbTZ+PjkyJnE30Uid64eHwbwa1Q25INCAYfZlK4o6ylagBy/Le9eWntqJFoFT93ikUKMv47GZ4gTwHkw==",
12 "dependencies": {}
13+ },
14+ "marked@4.2.4": {
15+ "integrity": "sha512-Wcc9ikX7Q5E4BYDPvh1C6QNSxrjC9tBgz+A/vAhp59KXUgachw++uMvMKiSW8oA85nopmPZcEvBoex/YLMsiyA==",
16+ "dependencies": {}
17 }
18 }
19 }
+5,
-1
1@@ -49,7 +49,11 @@ function processMarkdown(text: string) {
2 // hardcoded deny-list for headings
3 for (let i = 0; i < headings.length; i += 1) {
4 const heading = headings[i];
5- if (["contents", "vim", "ui", "wishlist", "resource"].includes(heading)) return;
6+ if (
7+ ["contents", "vim", "ui", "wishlist", "resource"].includes(
8+ heading,
9+ )
10+ ) return;
11 }
12
13 const tags = headings.map(sanitizeTag);
+16,
-11
1@@ -158,9 +158,11 @@ const createPluginItem = (plugin: Plugin, tags: Tag[]) => {
2
3 let repoLink = `
4 <a href=${plugin.link} class="flex">${createIcon("github")}</a>
5- <div class="metric-item">${createIcon("star")} <span>${nf.format(
6- plugin.stars
7- )}</span></div>
8+ <div class="metric-item">${createIcon("star")} <span>${
9+ nf.format(
10+ plugin.stars,
11+ )
12+ }</span></div>
13 <div class="metric-item">
14 ${createIcon("alert-circle")} <span>${nf.format(plugin.openIssues)}</span>
15 </div>`;
16@@ -264,7 +266,7 @@ const createSearchPage = (data: PluginData, by: keyof Plugin) => {
17 }, "");
18 const tagListStr = data.tags.reduce(
19 (acc, tag) => `${acc}\n${createTag(tag)}`,
20- ""
21+ "",
22 );
23 const sortStr = () => {
24 let str = "";
25@@ -332,7 +334,7 @@ const createSearchPage = (data: PluginData, by: keyof Plugin) => {
26 <div class="plugins">
27 <div class="plugins_container">
28 <div class="search_results">${data.plugins.length} results</div>
29- <div>
30+ <div id="sort_links">
31 ${sortStr()}
32 </div>
33 <div id="plugins_list">
34@@ -417,9 +419,11 @@ const createPluginPage = (plugin: Plugin, tags: Tag[], html: string) => {
35 <div class="header">
36 <h2>${plugin.id}</h2>
37 ${plugin.homepage ? `<a href=${plugin.homepage}>website</a>` : ""}
38- <a href=${plugin.link} class="flex">${createIcon(
39- "github"
40- )} <span>github</span></a>
41+ <a href=${plugin.link} class="flex">${
42+ createIcon(
43+ "github",
44+ )
45+ } <span>github</span></a>
46 </div>
47 ${createPluginView(plugin, tags)}
48 ${html}
49@@ -434,11 +438,11 @@ async function render(data: PluginData, htmlData: { [key: string]: string }) {
50 createFile("./static/index.html", createSearchPage(data, "stars")),
51 createFile(
52 "./static/created/index.html",
53- createSearchPage(data, "createdAt")
54+ createSearchPage(data, "createdAt"),
55 ),
56 createFile(
57 "./static/updated/index.html",
58- createSearchPage(data, "updatedAt")
59+ createSearchPage(data, "updatedAt"),
60 ),
61 createFile("./static/about/index.html", createAboutPage()),
62 ];
63@@ -447,7 +451,8 @@ async function render(data: PluginData, htmlData: { [key: string]: string }) {
64 const tags = getTags(data.tagDb, plugin.tags);
65 const id = `${plugin.username}/${plugin.repo}`;
66 const html = htmlData[id] || "";
67- const fname = `./static/plugin/${plugin.username}/${plugin.repo}/index.html`;
68+ const fname =
69+ `./static/plugin/${plugin.username}/${plugin.repo}/index.html`;
70 const page = createPluginPage(plugin, tags, html);
71 files.push(createFile(fname, page));
72 });
+17,
-0
1@@ -60,6 +60,20 @@ function createFilter(pluginsEl) {
2 return filter;
3 }
4
5+function updateLinks(search) {
6+ const links = must("#sort_links");
7+ for (let link of links.children) {
8+ const r = new URL(link.href);
9+ if (search) {
10+ r.searchParams.set("search", search);
11+ } else {
12+ r.searchParams.delete("search");
13+ }
14+ const newUrl = r.href;
15+ link.href = newUrl;
16+ }
17+}
18+
19 function must(pattern) {
20 const el = document.querySelector(pattern);
21 if (!el) {
22@@ -89,8 +103,10 @@ function init() {
23 const search = (value) => {
24 if (value) {
25 addUrlParam("search", value);
26+ updateLinks(value);
27 } else {
28 rmUrlParam("search");
29+ updateLinks("");
30 }
31
32 filter(value);
33@@ -104,6 +120,7 @@ function init() {
34 clearSearchEl.addEventListener("click", () => {
35 searchEl.value = "";
36 rmUrlParam("search");
37+ updateLinks("");
38 filter("");
39 });
40