Add option for query id routing (#31)
This commit is contained in:
45
.github/workflows/pages.yml
vendored
Normal file
45
.github/workflows/pages.yml
vendored
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
name: Deploy to GitHub Pages
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
pages: write
|
||||||
|
id-token: write
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: 'pages'
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
environment:
|
||||||
|
name: github-pages
|
||||||
|
url: ${{ steps.deployment.outputs.page_url }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Set up Node
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: lts/*
|
||||||
|
cache: 'npm'
|
||||||
|
- name: Install dependencies
|
||||||
|
run: yarn install --frozen-lockfile
|
||||||
|
- name: Build
|
||||||
|
run: yarn build
|
||||||
|
env:
|
||||||
|
#VITE_BYTEBIN_URL: "https://your-bytebin.example.com/"
|
||||||
|
VITE_USE_QUERY_ROUTING: "true" # required for github pages
|
||||||
|
- name: Setup Pages
|
||||||
|
uses: actions/configure-pages@v5
|
||||||
|
- name: Upload artifact
|
||||||
|
uses: actions/upload-pages-artifact@v3
|
||||||
|
with:
|
||||||
|
# Upload dist folder
|
||||||
|
path: './dist'
|
||||||
|
- name: Deploy to GitHub Pages
|
||||||
|
id: deployment
|
||||||
|
uses: actions/deploy-pages@v4
|
||||||
11
src/App.tsx
11
src/App.tsx
@@ -5,6 +5,7 @@ import Editor from './components/Editor';
|
|||||||
import usePreference from './hooks/usePreference.ts';
|
import usePreference from './hooks/usePreference.ts';
|
||||||
import themes, { Themes } from './style/themes.ts';
|
import themes, { Themes } from './style/themes.ts';
|
||||||
import { loadFromBytebin } from './util/storage';
|
import { loadFromBytebin } from './util/storage';
|
||||||
|
import { useQueryRouting } from './util/constants';
|
||||||
|
|
||||||
const INITIAL = Symbol();
|
const INITIAL = Symbol();
|
||||||
const LOADING = Symbol();
|
const LOADING = Symbol();
|
||||||
@@ -81,10 +82,10 @@ function get404Message(pasteId: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getPasteIdFromUrl() {
|
function getPasteIdFromUrl() {
|
||||||
|
if (useQueryRouting) {
|
||||||
|
return new URLSearchParams(window.location.search).get('id') ?? undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const path = window.location.pathname;
|
const path = window.location.pathname;
|
||||||
if (path && /^\/[a-zA-Z0-9]+$/.test(path)) {
|
return /^\/[a-zA-Z0-9]+$/.test(path) ? path.substring(1) : undefined;
|
||||||
return path.substring(1);
|
|
||||||
} else {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import styled from 'styled-components';
|
|||||||
import themes, { Themes } from '../style/themes';
|
import themes, { Themes } from '../style/themes';
|
||||||
import { languages } from '../util/highlighting';
|
import { languages } from '../util/highlighting';
|
||||||
import { saveToBytebin } from '../util/storage';
|
import { saveToBytebin } from '../util/storage';
|
||||||
|
import { useQueryRouting } from '../util/constants';
|
||||||
import Button from './Button';
|
import Button from './Button';
|
||||||
import { ResetFunction } from './Editor';
|
import { ResetFunction } from './Editor';
|
||||||
import MenuButton from './MenuButton';
|
import MenuButton from './MenuButton';
|
||||||
@@ -59,9 +60,15 @@ export default function EditorControls({
|
|||||||
setSaving(false);
|
setSaving(false);
|
||||||
setRecentlySaved(true);
|
setRecentlySaved(true);
|
||||||
if (pasteId) {
|
if (pasteId) {
|
||||||
|
if (useQueryRouting) {
|
||||||
|
history.replace({
|
||||||
|
search: `?id=${pasteId}`,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
history.replace({
|
history.replace({
|
||||||
pathname: pasteId,
|
pathname: pasteId,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
copy(window.location.href);
|
copy(window.location.href);
|
||||||
document.title = 'paste | ' + pasteId;
|
document.title = 'paste | ' + pasteId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
export const bytebinUrl =
|
export const bytebinUrl =
|
||||||
import.meta.env.VITE_BYTEBIN_URL || 'https://bytebin.lucko.me/';
|
import.meta.env.VITE_BYTEBIN_URL || 'https://bytebin.lucko.me/';
|
||||||
export const postUrl = bytebinUrl + 'post';
|
export const postUrl = bytebinUrl + 'post';
|
||||||
|
export const useQueryRouting =
|
||||||
|
import.meta.env.VITE_USE_QUERY_ROUTING === 'true';
|
||||||
|
|||||||
1
src/vite-env.d.ts
vendored
1
src/vite-env.d.ts
vendored
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
interface ImportMetaEnv {
|
interface ImportMetaEnv {
|
||||||
readonly VITE_BYTEBIN_URL?: string;
|
readonly VITE_BYTEBIN_URL?: string;
|
||||||
|
readonly VITE_USE_QUERY_ROUTING?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ImportMeta {
|
interface ImportMeta {
|
||||||
|
|||||||
Reference in New Issue
Block a user