Skip to content

Commit

Permalink
Clean session param before using in origin and url term
Browse files Browse the repository at this point in the history
  • Loading branch information
laymonage committed Nov 20, 2021
1 parent d5b9655 commit 17686cd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ loadScript(`${giscusOrigin}/js/iframeResizer.min.js`, () =>
const url = new URL(location.href);
let session = url.searchParams.get('giscus');
const savedSession = localStorage.getItem(GISCUS_SESSION_KEY);
url.searchParams.delete('giscus');
const cleanedLocation = url.toString();

if (session) {
localStorage.setItem(GISCUS_SESSION_KEY, JSON.stringify(session));
url.searchParams.delete('giscus');
history.replaceState(undefined, document.title, url.toString());
history.replaceState(undefined, document.title, cleanedLocation);
} else {
try {
session = JSON.parse(savedSession) || '';
Expand All @@ -45,7 +46,7 @@ const ogDescriptionMeta = document.querySelector(
`meta[property='og:description'],meta[name='description']`,
) as HTMLMetaElement;

params.origin = location.href;
params.origin = cleanedLocation;
params.session = session;
params.theme = attributes.theme;
params.reactionsEnabled = attributes.reactionsEnabled || '1';
Expand All @@ -58,7 +59,7 @@ params.description = ogDescriptionMeta ? ogDescriptionMeta.content : '';

switch (attributes.mapping) {
case 'url':
params.term = location.href;
params.term = cleanedLocation;
break;
case 'title':
params.term = document.title;
Expand Down

1 comment on commit 17686cd

@vercel
Copy link

@vercel vercel bot commented on 17686cd Nov 20, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.