Skip to content

Commit

Permalink
remove url queries after use
Browse files Browse the repository at this point in the history
  • Loading branch information
leomcelroy committed Oct 20, 2023
1 parent 9d4e114 commit ff55a04
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions astro/src/components/Help.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import styles from './Help.module.css'
import { useState, useEffect } from 'preact/hooks'
import { marked } from 'marked'
import { loadCodeFromString } from "../lib/loadCodeFromString.ts";
import { removeQueryParam } from "../lib/removeQueryParam.js";

marked.setOptions({
highlight: function (code, language) {
Expand Down Expand Up @@ -41,8 +42,12 @@ export default function Help({

if (workshop === null) return


if (confirm("Clear text editor?")) loadCodeFromString("");

removeQueryParam("guide");


const res = await fetch(
`https://raw.githubusercontent.com/hackclub/blot/main/guides/${workshop}.md`
)
Expand Down
2 changes: 2 additions & 0 deletions astro/src/lib/events/addSrcURLParam.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { loadCodeFromString } from '../loadCodeFromString.ts'
import { removeQueryParam } from "../removeQueryParam.js";

export async function addSrcURLParam() {
const currentUrl = new URL(window.location.href)
Expand All @@ -12,6 +13,7 @@ export async function addSrcURLParam() {
const content = await response.text()

loadCodeFromString(content)
removeQueryParam("src")
} catch (error) {
console.error('Error fetching content:', error)
}
Expand Down
16 changes: 16 additions & 0 deletions astro/src/lib/removeQueryParam.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export function removeQueryParam(paramName) {
// Get the current URL
let currentUrl = window.location.href;

// Create a URL object from the current URL
let urlObj = new URL(currentUrl);

// Remove the query parameter
urlObj.searchParams.delete(paramName);

// Get the resulting URL string, after the parameter removal
let newUrl = urlObj.toString();

// Update the URL displayed in the browser without reloading the page
history.replaceState({}, null, newUrl);
}

1 comment on commit ff55a04

@vercel
Copy link

@vercel vercel bot commented on ff55a04 Oct 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

blot – ./astro

blot.hackclub.dev
blot-git-main.hackclub.dev

Please sign in to comment.