Skip to content

Commit

Permalink
chore: simplify/shorten html wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
ozwaldorf committed Oct 15, 2024
1 parent bb0b513 commit 15a1378
Showing 2 changed files with 70 additions and 96 deletions.
129 changes: 55 additions & 74 deletions src/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,77 +1,58 @@
<!DOCTYPE html>
<html>
<head>
<title>{host} - no bs pastebin</title>
<meta name="description" content="{host} - no bs command line pastebin">
<style>
@font-face {{
font-family: 'IBM Plex Mono';
src: url('https://cdn.jsdelivr.net/npm/@xz/fonts@1/serve/src/ibm-plex-mono/IBMPlexMono.woff2') format('woff2'),
url('https://cdn.jsdelivr.net/npm/@xz/fonts@1/serve/src/ibm-plex-mono/IBMPlexMono.woff') format('woff');
font-weight: normal;
font-style: normal;
font-display: swap;
<head>
<title>{host} - no bs pastebin</title>
<meta name="description" content="{host} - no bs command line pastebin">
<style>
@font-face {{
font-family: 'IBM Plex Mono'; font-weight: normal; font-style: normal; font-display: swap;
src: url('https://cdn.jsdelivr.net/npm/@xz/fonts@1/serve/src/ibm-plex-mono/IBMPlexMono.woff2') format('woff2'),
url('https://cdn.jsdelivr.net/npm/@xz/fonts@1/serve/src/ibm-plex-mono/IBMPlexMono.woff') format('woff'); }}
body {{ font-family: 'IBM Plex Mono', monospace; font-size: 1em; color: #f4f4f4; background: #0b0b0b; }}
pre {{ max-width: 73ch; margin: 0 auto; }}
a {{ color: #78a9ff; }}
</style>
<script nonce="{nonce}">
// Upload a file and return the url
async function upload(data, name = "") {{
const uploadUrl = `/${{name}}`;
try {{
const response = await fetch(uploadUrl, {{
method: 'PUT',
body: data
}});
const responseBody = await response.text();
return response.ok
? `<a href="${{responseBody}}" target="_blank">${{responseBody}}</a>`
: `Failed to upload "${{uploadUrl}}": ${{response.statusText}}`;
}} catch (error) {{
return `Error uploading "${{uploadUrl}}": ${{error.message}}`;
}}
body {{
color: #f4f4f4;
background: #0b0b0b;
font-family: 'IBM Plex Mono', monospace;
font-size: 1em;
}}
// Listen for ctrl/cmd + V
document.addEventListener('paste', async (event) => {{
const preElement = document.querySelector('pre');
preElement.innerHTML = "Uploading...";
const text = event.clipboardData.getData("text");
if (text) {{
preElement.innerHTML = await upload(text);
return;
}}
pre {{
max-width: 73ch;
margin: 0 auto;
}}
a {{ color: #78a9ff; }}
</style>
<script nonce="{nonce}">
// Upload a file and return the url
async function upload(data, name = "") {{
const uploadUrl = `/${{name}}`;
try {{
const response = await fetch(uploadUrl, {{
method: 'PUT',
body: data
}});
const responseBody = await response.text();
return response.ok
? `<a href="${{responseBody}}" target="_blank">${{responseBody}}</a>`
: `Failed to upload "${{uploadUrl}}": ${{response.statusText}}`;
}} catch (error) {{
return `Error uploading "${{uploadUrl}}": ${{error.message}}`;
}}
}}

// Listen for ctrl/cmd + V
document.addEventListener('paste', async (event) => {{
const preElement = document.querySelector('pre');
preElement.innerHTML = "Uploading...";
const text = event.clipboardData.getData("text");
if (text) {{
preElement.innerHTML = await upload(text);
return;
}}
const responses = await Promise.all([...event.clipboardData.items]
.filter(item => item.kind === 'file')
.map(async item => {{
const file = item.getAsFile();
if (!file)
return `Error reading from clipboard`;
return await upload(file, file.name)
}})
);
preElement.innerHTML = responses.join('\n');
}});


// Replace urls with links on page load
document.addEventListener('DOMContentLoaded', () => {{
const preElement = document.querySelector('pre');
preElement.innerHTML = preElement.innerHTML.replace(/((https:)[^\s]+[\w])/g, '<a href="$1" target="_blank">$1</a>');
}}, false);
</script>
</head>
<body>
<pre>{body}</pre>
</body>
</html>
const responses = await Promise.all([...event.clipboardData.items]
.filter(item => item.kind === 'file')
.map(async item => {{
const file = item.getAsFile();
if (!file)
return `Error reading from clipboard`;
return await upload(file, file.name)
}})
);
preElement.innerHTML = responses.join('\n');
}});
// Replace urls with links on page load
document.addEventListener('DOMContentLoaded', () => {{
const preElement = document.querySelector('pre');
preElement.innerHTML = preElement.innerHTML.replace(/((https:)[^\s]+[\w])/g, '<a href="$1" target="_blank">$1</a>');
}}, false);
</script>
</head>
<body><pre>{body}</pre></body>
37 changes: 15 additions & 22 deletions src/templates/privacy.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>{host} - privacy policy</title>
<meta name="description" content="{host} privacy policy">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@xz/fonts@1/serve/ibm-plex-mono.min.css">
<style>
body {{
color: #f4f4f4;
background: #0b0b0b;
}}
pre {{
font-family: 'IBM Plex Mono', monospace;
font-size: 1em;
max-width: 73ch;
margin: 0 auto;
}}
</style>
</head>
<body>
<pre>{body}</pre>
</body>
</html>
<head>
<title>{host} - privacy policy</title>
<meta name="description" content="{host} privacy policy">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@xz/fonts@1/serve/ibm-plex-mono.min.css">
<style>
@font-face {{
font-family: 'IBM Plex Mono'; font-weight: normal; font-style: normal; font-display: swap;
src: url('https://cdn.jsdelivr.net/npm/@xz/fonts@1/serve/src/ibm-plex-mono/IBMPlexMono.woff2') format('woff2'),
url('https://cdn.jsdelivr.net/npm/@xz/fonts@1/serve/src/ibm-plex-mono/IBMPlexMono.woff') format('woff'); }}
body {{ font-family: 'IBM Plex Mono', monospace; font-size: 1em; color: #f4f4f4; background: #0b0b0b; }}
pre {{ max-width: 73ch; margin: 0 auto; }}
a {{ color: #78a9ff; }}
</style>
</head>
<body><pre>{body}</pre></body>

0 comments on commit 15a1378

Please sign in to comment.