Skip to content

Commit 1d53659

Browse files
authored
Merge branch 'main' into copilot/update-dependencies-bump-node
2 parents 6e9ab71 + bdd5040 commit 1d53659

File tree

13 files changed

+8568
-144
lines changed

13 files changed

+8568
-144
lines changed

.github/workflows/demo.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# From https://github.blog/changelog/2022-07-27-github-pages-custom-github-actions-workflows-beta/
2+
name: Demo
3+
4+
on:
5+
- pull_request
6+
- push
7+
8+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- run: npm ci
20+
- run: npm run build:demo
21+
- name: Upload artifact
22+
uses: actions/upload-pages-artifact@v3
23+
with:
24+
path: demo/dist/
25+
26+
deploy:
27+
# Allow one concurrent deployment
28+
concurrency:
29+
group: 'pages'
30+
cancel-in-progress: true
31+
32+
environment:
33+
name: github-pages
34+
url: ${{ steps.deployment.outputs.page_url }}
35+
runs-on: ubuntu-latest
36+
needs: build
37+
if: github.ref == 'refs/heads/main'
38+
steps:
39+
- name: Deploy to GitHub Pages
40+
id: deployment
41+
uses: actions/deploy-pages@v4

.github/workflows/main.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ on:
44
- pull_request
55
- push
66

7+
permissions:
8+
contents: read
9+
710
jobs:
811
Lint:
912
runs-on: ubuntu-latest
@@ -34,3 +37,13 @@ jobs:
3437
node-version-file: package.json
3538
- run: npm install
3639
- run: npx vitest
40+
41+
Demo:
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v4
45+
- uses: actions/setup-node@v4
46+
with:
47+
node-version-file: package.json
48+
- run: npm install
49+
- run: npm run build:demo

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ Thumbs.db
66
*.tmp
77
*.bak
88
*.log
9-
*.lock
109
logs
11-
package-lock.json
10+
demo/dist

.npmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
package-lock=false
1+
package-lock=true

demo/global.css

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
* {
2+
transition: none !important;
3+
}
4+
5+
:root {
6+
--grid-maxWidth: 800px;
7+
--color-primary: #4a8a00;
8+
padding-bottom: 3rem;
9+
-moz-tab-size: 4;
10+
tab-size: 4;
11+
}
12+
13+
code {
14+
color: var(--color-darkGrey);
15+
background-color: rgba(175, 184, 193, 0.2);
16+
padding: 0.2em 0.4em;
17+
border-radius: 3px;
18+
}
19+
20+
h1 {
21+
background: #4a8a00;
22+
padding: 1em;
23+
margin-top: 0;
24+
text-align: center;
25+
}
26+
27+
h1 a {
28+
color: white;
29+
}
30+
31+
label {
32+
display: flex;
33+
align-items: center;
34+
margin-bottom: 1em;
35+
}
36+
37+
label span {
38+
margin-right: 0.5em;
39+
font-size: 1.7em;
40+
font-weight: bold;
41+
}
42+
43+
input {
44+
width: 100%;
45+
}
46+
47+
#output {
48+
margin: 2em 0;
49+
padding: 1em;
50+
background-color: #f6f8fa;
51+
border-radius: 6px;
52+
min-height: 2em;
53+
}
54+
55+
#output.has-content {
56+
border: 1px solid #d0d7de;
57+
}
58+
59+
#output .result {
60+
font-size: 1.2em;
61+
margin-bottom: 0.5em;
62+
}
63+
64+
#output .original {
65+
font-size: 0.9em;
66+
color: #57606a;
67+
margin-top: 0.5em;
68+
}
69+
70+
.example {
71+
margin: 1em 0;
72+
padding: 1em;
73+
background-color: #f6f8fa;
74+
border-radius: 6px;
75+
border: 1px solid #d0d7de;
76+
}
77+
78+
.example-url {
79+
font-family: monospace;
80+
font-size: 0.9em;
81+
color: #0969da;
82+
word-break: break-all;
83+
margin-bottom: 0.5em;
84+
}
85+
86+
.example-result {
87+
font-size: 1.1em;
88+
margin-top: 0.5em;
89+
padding-top: 0.5em;
90+
border-top: 1px solid #d0d7de;
91+
}

demo/index.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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>`shorten-repo-url` npm module testing ground</title>
12+
13+
<link rel="stylesheet" href="global.css" />
14+
<script defer type="module" src="index.js"></script>
15+
</head>
16+
17+
<body>
18+
<h1>
19+
<a href="https://github.com/refined-github/shorten-repo-url">
20+
refined-github/shorten-repo-url
21+
</a>
22+
</h1>
23+
<main class="container">
24+
<p>
25+
Enter a GitHub URL to see how it will be shortened.
26+
</p>
27+
<label>
28+
<span>URL:</span>
29+
<input
30+
type="search"
31+
id="url-input"
32+
placeholder="https://github.com/nodejs/node/tree/v0.12/doc"
33+
autocomplete="off"
34+
autocorrect="off"
35+
/>
36+
</label>
37+
<div id="output"></div>
38+
<h2>Examples</h2>
39+
<div id="examples"></div>
40+
</main>
41+
</body>
42+
</html>

demo/index.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import shortenUrl from '../index.js';
2+
import {urls} from '../fixtures/urls.js';
3+
4+
const currentLocation = 'https://github.com/fregante/shorten-repo-url/issue/1';
5+
6+
const urlInput = document.querySelector('#url-input');
7+
const output = document.querySelector('#output');
8+
const examplesContainer = document.querySelector('#examples');
9+
10+
function updateOutput(url) {
11+
if (!url) {
12+
output.innerHTML = '';
13+
output.classList.remove('has-content');
14+
return;
15+
}
16+
17+
const shortened = shortenUrl(url, currentLocation);
18+
19+
if (shortened) {
20+
output.classList.add('has-content');
21+
output.innerHTML = `
22+
<div class="result">${shortened}</div>
23+
<div class="original">Original: ${url}</div>
24+
`;
25+
} else {
26+
output.classList.add('has-content');
27+
output.innerHTML = `
28+
<div class="result">Not a GitHub URL or unable to shorten</div>
29+
<div class="original">Original: ${url}</div>
30+
`;
31+
}
32+
}
33+
34+
// Handle input changes
35+
urlInput.addEventListener('input', event => {
36+
updateOutput(event.target.value);
37+
});
38+
39+
// Initialize examples
40+
function renderExamples() {
41+
examplesContainer.innerHTML = urls.map(url => {
42+
const shortened = shortenUrl(url, currentLocation);
43+
return `
44+
<div class="example">
45+
<div class="example-url">${url}</div>
46+
<div class="example-result">→ ${shortened || 'Not shortened'}</div>
47+
</div>
48+
`;
49+
}).join('');
50+
}
51+
52+
renderExamples();

demo/vite.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {defineConfig} from 'vite';
2+
3+
export default defineConfig({
4+
base: '',
5+
build: {
6+
outDir: 'dist',
7+
emptyOutDir: true,
8+
},
9+
});

0 commit comments

Comments
 (0)