Skip to content

Commit

Permalink
fix: corriger liens en deploiement
Browse files Browse the repository at this point in the history
  • Loading branch information
dhdaines committed Feb 7, 2024
1 parent 0a68197 commit 2981439
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { ALEXI_URL } from "./config.ts";
import INDEX_URL from "/index.json?url";
// @ts-ignore
import TEXTES_URL from "/textes.json?url";
// @ts-ignore
const BASE_URL = import.meta.env.BASE_URL;

interface Texte {
titre: string;
Expand Down Expand Up @@ -44,7 +46,7 @@ class App {
target.innerHTML = "";
const result = await fetch(source);
if (!result.ok) {
target.innerHTML = `Error in fetch: ${result}`;
target.innerHTML = `Error in fetch: ${result.status}`;
return;
}
const content = await result.text();
Expand Down Expand Up @@ -76,14 +78,14 @@ class App {

follow_link(e: Event, url: string, query: string) {
this.show_document(url);
history.pushState(null, "", `/alexi/${url}?q=${query}`)
history.pushState(null, "", `${BASE_URL}${url}?q=${query}`)
e.preventDefault();
}

create_title(titre: string, query: string, result: lunr.Index.Result) {
const a = document.createElement("a");
// FIXME: should be shared with follow_link
a.href = `/alexi/${result.ref}?q=${query}`;
a.href = `${BASE_URL}${result.ref}?q=${query}`;
a.innerText = titre;
a.addEventListener("click", e => this.follow_link(e, result.ref, query));
return a;
Expand Down Expand Up @@ -148,10 +150,11 @@ class App {
if (text.length < 2)
return;
const query = encodeURIComponent(text);
/* Ensure that the URL matches the display if we bookmark/reload */
if (this.media_query.matches)
history.replaceState(null, "", `?q=${query}`)
else
history.replaceState(null, "", `/?q=${query}`)
history.replaceState(null, "", `${BASE_URL}?q=${query}`)
try {
const results = this.index.search(text);
this.search_results.innerHTML = "";
Expand All @@ -165,11 +168,12 @@ class App {

/* Do asynchronous initialization things */
async initialize() {
/* Like showing a document if requested */
const parts = window.location.pathname.split("/").filter(x => x.length);
let showing = false;
if (parts.length > 1 && parts[0] === "alexi") {
this.show_document(parts.slice(1).join("/"))
if (window.location.pathname != BASE_URL) {
/* We *know* that it will start with BASE_URL, because we
* constructed it that way. If not, fetch will just fail, which
* is okay too. */
this.show_document(window.location.pathname.substring(BASE_URL.length));
showing = true;
}
/* Load the index / text if possible (FIXME: will possibly use an ALEXI API here) */
Expand Down

0 comments on commit 2981439

Please sign in to comment.