-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from sjdonado/base64-id-ssr-link-preview
Base64 id ssr link preview
- Loading branch information
Showing
25 changed files
with
185 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
name: Run tests | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export const generateId = (source: string) => { | ||
const parsedUrl = new URL(source); | ||
|
||
// Remove the protocol | ||
const hostname = parsedUrl.hostname; | ||
const pathname = parsedUrl.pathname; | ||
const search = parsedUrl.search || ''; | ||
|
||
// Get the first query parameter | ||
const queryParams = new URLSearchParams(search); | ||
const firstParam = queryParams.entries().next().value; | ||
|
||
let idString = `${hostname}${pathname}`; | ||
if (firstParam) { | ||
idString += `?${firstParam[0]}=${firstParam[1]}`; | ||
} | ||
|
||
return encodeURIComponent(Buffer.from(idString).toString('base64')); | ||
}; | ||
|
||
export const getSourceFromId = (id: string) => { | ||
const decoded = decodeURIComponent(Buffer.from(id, 'base64').toString('utf8')); | ||
|
||
return `https://${decoded}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,32 @@ | ||
export default function SearchBar() { | ||
export default function SearchBar({ source }: { source?: string }) { | ||
return ( | ||
<> | ||
<form | ||
id="search-form" | ||
hx-post="/search" | ||
hx-target="#search-results" | ||
hx-swap="innerHTML" | ||
hx-indicator="#loading-indicator" | ||
hx-request='\"timeout\":6000' | ||
class="flex w-full max-w-3xl items-center justify-center" | ||
<form | ||
id="search-form" | ||
hx-post="/search" | ||
hx-target="#search-results" | ||
hx-swap="innerHTML" | ||
hx-indicator="#loading-indicator" | ||
hx-request='\"timeout\":6000' | ||
class="flex w-full max-w-3xl items-center justify-center px-2" | ||
> | ||
<label for="song-link" class="sr-only"> | ||
Search | ||
</label> | ||
<input | ||
type="text" | ||
id="song-link" | ||
name="link" | ||
class="flex-1 rounded-lg border bg-white p-2.5 text-sm font-normal text-black placeholder:text-gray-400 lg:text-base" | ||
placeholder="https://open.spotify.com/track/7A8MwSsu9efJXP6xvZfRN3?si=d4f1e2eb324c43df" | ||
value={source} | ||
/> | ||
<button | ||
type="submit" | ||
class="ml-2 rounded-lg border border-green-500 bg-green-500 p-2.5 text-sm font-medium text-white focus:outline-none focus:ring-1 focus:ring-white" | ||
> | ||
<label for="song-link" class="sr-only"> | ||
Search | ||
</label> | ||
<input | ||
type="text" | ||
id="song-link" | ||
name="link" | ||
class="flex-1 rounded-lg border bg-white p-2.5 text-sm font-normal text-black placeholder:text-gray-400 lg:text-base" | ||
placeholder="https://open.spotify.com/track/7A8MwSsu9efJXP6xvZfRN3?si=d4f1e2eb324c43df" | ||
/> | ||
<button | ||
type="submit" | ||
class="ml-2 rounded-lg border border-green-500 bg-green-500 p-2.5 text-sm font-medium text-white focus:outline-none focus:ring-1 focus:ring-white" | ||
> | ||
<i class="fas fa-search p-1 text-black" /> | ||
<span class="sr-only">Search</span> | ||
</button> | ||
</form> | ||
<div class="my-4"> | ||
<div id="search-results" /> | ||
</div> | ||
</> | ||
<i class="fas fa-search p-1 text-black" /> | ||
<span class="sr-only">Search</span> | ||
</button> | ||
</form> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './search-bar'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.