Skip to content

Commit cf06543

Browse files
authored
Add detections list page (#164)
1 parent 3a850c1 commit cf06543

File tree

8 files changed

+85
-7
lines changed

8 files changed

+85
-7
lines changed

collector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @file This needs to be in a separate file so it can bee tree-shaken before being published, while still being importable by tests */
22

3-
const testableUrls = new Map<string, string[]>();
3+
export const testableUrls = new Map<string, string[]>();
44

55
export function addTests(test: string, urls: string[]): void {
66
// @ts-expect-error KISS for Vite

demo/Detections.svelte

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<script>
2+
import * as urlDetection from '../index';
3+
import { getTests } from '../collector';
4+
</script>
5+
6+
<style>
7+
pre, code {
8+
white-space: nowrap;
9+
}
10+
pre a {
11+
color: inherit;
12+
}
13+
</style>
14+
{#each Object.keys(urlDetection) as name}
15+
{#if !name.startsWith('_') && name !== 'utils'}
16+
<h2 id={name}><a href="#{name}">{name}</a></h2>
17+
{@const urls = getTests(name)}
18+
{#if urls[0] === 'combinedTestOnly'}
19+
<p><em>Demo URLs missing</em></p>
20+
{:else if urls.length === 0}
21+
<p><em>Undeterminable via URL</em></p>
22+
{:else}
23+
<pre><code>
24+
{#each urls as url}
25+
<a href="/?url={encodeURIComponent(url)}">{url}</a><br>
26+
{/each}
27+
</code></pre>
28+
{/if}
29+
{/if}
30+
{/each}

demo/App.svelte renamed to demo/Index.svelte

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<script>
2-
32
import parseUrl from './parse-url.js';
43
import * as urlDetection from '../index';
5-
import { getAllUrls } from '../collector';
4+
import { getAllUrls, testableUrls } from '../collector';
65
76
const defaultUrl = 'https://github.com/refined-github/github-url-detection';
87
const urlParameter = new URLSearchParams(location.search);
@@ -75,6 +74,10 @@
7574
.undefined {
7675
color: gray;
7776
}
77+
78+
pre a {
79+
color: inherit;
80+
}
7881
</style>
7982

8083
<label>
@@ -99,7 +102,7 @@
99102
{#each detections as {name, detect, result} (name)}
100103
{#if detect}
101104
<div class={String(result)}>
102-
{name}(url) // <span>{String(result)}</span></div>
105+
<a href="/detections.html#{name}">{name}</a>(url) // <span>{String(result)}</span></div>
103106
{:else}
104107
<div class="undefined">
105108
{name}() // undeterminable via URL</div>

demo/detections.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link
6+
rel="stylesheet"
7+
href="https://unpkg.com/chota@0.7.2/dist/chota.min.css"
8+
/>
9+
<meta name="viewport" content="width=device-width,initial-scale=1" />
10+
11+
<title>`github-url-detection` detections</title>
12+
13+
<link rel="stylesheet" href="global.css" />
14+
<script defer type="module" src="detections.js"></script>
15+
</head>
16+
17+
<body>
18+
<h1>
19+
<a href="https://github.com/refined-github/github-url-detection">
20+
refined-github/github-url-detection
21+
</a>
22+
</h1>
23+
<main class="container">
24+
</main>
25+
</body>
26+
</html>

demo/detections.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Detections from './Detections.svelte';
2+
3+
const app = new Detections({
4+
target: document.querySelector('main'),
5+
});
6+
7+
export default app;

demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<title>`github-url-detection` npm module testing ground</title>
1212

1313
<link rel="stylesheet" href="global.css" />
14-
<script defer type="module" src="main.js"></script>
14+
<script defer type="module" src="index.js"></script>
1515
</head>
1616

1717
<body>

demo/main.js renamed to demo/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import App from './App.svelte';
1+
import Index from './Index.svelte';
22

3-
const app = new App({
3+
const app = new Index({
44
target: document.querySelector('main'),
55
});
66

demo/vite.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1+
import {resolve} from 'node:path';
2+
import * as url from 'node:url';
13
import {defineConfig} from 'vite';
24
import {svelte} from '@sveltejs/vite-plugin-svelte';
35

6+
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
7+
48
export default defineConfig({
59
base: '',
610
plugins: [svelte()],
11+
build: {
12+
rollupOptions: {
13+
input: {
14+
main: resolve(__dirname, 'index.html'),
15+
nested: resolve(__dirname, 'detections.html'),
16+
},
17+
},
18+
},
719
});

0 commit comments

Comments
 (0)