Skip to content

Commit b36f78d

Browse files
mgarbsclaude
andcommitted
Fix SEO: preserve old /hip/hip-NNN URLs and fix GitHub submit URL-too-long
- Old /hip/hip-NNN paths now load the SPA directly (no redirect). A Vite plugin copies index.html to 404.html at build time so GitHub Pages serves the app for all paths. The app detects the pathname and routes internally. - Fix "Submit on GitHub" wizard button: copy markdown to clipboard first, then open GitHub's new-file page with just the filename. Previously the full markdown was encoded in the URL query string, exceeding browser URL length limits for longer proposals. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Michael Garber <michael.garber@hashgraph.com>
1 parent 096bc85 commit b36f78d

2 files changed

Lines changed: 36 additions & 7 deletions

File tree

site/src/main.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ let sectionSorts = new Map();
202202
INIT
203203
============================================= */
204204
async function init() {
205+
// Support old /hip/hip-NNN paths — GitHub Pages serves 404.html (= index.html)
206+
// for unknown paths, so the SPA loads and we route based on the pathname.
207+
const pathMatch = window.location.pathname.match(/\/hip\/hip-(\d+)$/);
208+
if (pathMatch && !window.location.hash) {
209+
history.replaceState(null, '', window.location.pathname.replace(/\/hip\/hip-\d+$/, '') + '#hip-' + pathMatch[1]);
210+
}
211+
205212
initTheme();
206213

207214
const base = import.meta.env.BASE_URL;
@@ -1915,7 +1922,7 @@ function renderSubmitStep(form) {
19151922

19161923
const slug = wizardData.title ? wizardData.title.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '') : 'my-proposal';
19171924
const filename = `HIP/hip-${slug}.md`;
1918-
const ghUrl = `https://github.com/${REPO_OWNER}/${REPO_NAME}/new/main?filename=${encodeURIComponent(filename)}&value=${encodeURIComponent(md)}`;
1925+
const ghUrl = `https://github.com/${REPO_OWNER}/${REPO_NAME}/new/main?filename=${encodeURIComponent(filename)}`;
19191926

19201927
safeHTML(form, `
19211928
<h3>Review & Submit</h3>
@@ -1926,10 +1933,10 @@ function renderSubmitStep(form) {
19261933
</div>
19271934
` : `<p class="wz-success">All required fields are complete. Your HIP is ready to submit!</p>`}
19281935
<div class="wz-submit-options">
1929-
<a href="${esc(ghUrl)}" target="_blank" class="wz-submit-btn wz-submit-btn--primary ${!allValid ? 'wz-submit-btn--disabled' : ''}">
1936+
<button class="wz-submit-btn wz-submit-btn--primary ${!allValid ? 'wz-submit-btn--disabled' : ''}" id="wz-github">
19301937
<svg width="18" height="18" viewBox="0 0 16 16" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg>
19311938
Submit on GitHub
1932-
</a>
1939+
</button>
19331940
<button class="wz-submit-btn wz-submit-btn--secondary" id="wz-download">
19341941
<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor"><path d="M7.47 10.78a.75.75 0 001.06 0l3.75-3.75a.75.75 0 00-1.06-1.06L8.75 8.44V1.75a.75.75 0 00-1.5 0v6.69L4.78 5.97a.75.75 0 00-1.06 1.06l3.75 3.75zM3.75 13a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5z"/></svg>
19351942
Download .md
@@ -1948,10 +1955,17 @@ function renderSubmitStep(form) {
19481955
</div>
19491956
`);
19501957

1951-
if (!allValid) {
1952-
const ghLink = form.querySelector('.wz-submit-btn--primary');
1953-
ghLink.addEventListener('click', e => e.preventDefault());
1954-
}
1958+
form.querySelector('#wz-github')?.addEventListener('click', () => {
1959+
if (!allValid) return;
1960+
navigator.clipboard.writeText(generateHipMarkdown()).then(() => {
1961+
window.open(ghUrl, '_blank');
1962+
// Show a brief notification that content was copied
1963+
const btn = form.querySelector('#wz-github');
1964+
const orig = btn.textContent;
1965+
btn.textContent = 'Copied to clipboard \u2014 paste into the editor on GitHub';
1966+
setTimeout(() => { btn.textContent = orig; }, 5000);
1967+
});
1968+
});
19551969

19561970
form.querySelector('#wz-download')?.addEventListener('click', () => {
19571971
const blob = new Blob([generateHipMarkdown()], { type: 'text/markdown' });

site/vite.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
import { defineConfig } from 'vite';
2+
import fs from 'fs';
3+
import path from 'path';
4+
5+
// Copy index.html → 404.html so GitHub Pages serves the SPA for all paths
6+
// (e.g. /hip/hip-1341). The app reads the pathname and routes internally.
7+
function copy404Plugin() {
8+
return {
9+
name: 'copy-404',
10+
closeBundle() {
11+
const dist = path.resolve(import.meta.dirname, 'dist');
12+
fs.copyFileSync(path.join(dist, 'index.html'), path.join(dist, '404.html'));
13+
},
14+
};
15+
}
216

317
export default defineConfig({
418
root: '.',
519
publicDir: 'public',
620
base: process.env.VITE_BASE || '/',
21+
plugins: [copy404Plugin()],
722
});

0 commit comments

Comments
 (0)