Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX-37] Relative urls with a harcoded contextPath #38

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function jsonToArray(json) {
}

function App() {
const appContextPath = process.env.PUBLIC_URL + "/";
// keeps the state of the json
const [data, setData] = useState(undefined);
// put all books into one array. uses more memory, but search is faster and less complex
Expand Down Expand Up @@ -89,13 +90,13 @@ function App() {
async function fetchData() {
try {
setQueries(queryString.parse(document.location.search));
if (queries.lang) {
if (queries.lang === "langs" || queries.lang === "subjects") {
changeParameter("lang.code", "en");
} else {
changeParameter("lang.code", queries.lang);
}
}
if (queries.lang) {
if (queries.lang === "langs" || queries.lang === "subjects") {
changeParameter("lang.code", "en");
} else {
changeParameter("lang.code", queries.lang);
}
}
// setLoading(true);
let result = await axios.get(
"https://raw.githubusercontent.com/EbookFoundation/free-programming-books-search/main/fpb.json"
Expand Down Expand Up @@ -201,7 +202,7 @@ function App() {
// lang: entry.item.lang,
// section: entry.item.section,
// title: `List of all ${section} books in ${entry.item.lang.name}`,
// url: `/free-programming-books-search?sect=books&lang=${langCode}&file=free-programming-books-${langCode}#${section}`,
// url: `${appContextPath}?sect=books&lang=${langCode}&file=free-programming-books-${langCode}#${section}`,
// samePage: true,
// },
// };
Expand Down Expand Up @@ -253,7 +254,7 @@ function App() {
</ThemeContext.Consumer>
<header className="header">
<h1>
<a href="/free-programming-books-search/">free-programming-books</a>
<a href={`${appContextPath}`}>free-programming-books</a>
</h1>

<p>
Expand Down
7 changes: 4 additions & 3 deletions src/components/ParsedLink.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState, useEffect } from "react";

function ParsedLink({ children, sect, href, id }) {
const appContextPath = process.env.PUBLIC_URL + "/";
const [folder, setFolder] = useState(null);
const [file, setFile] = useState(null);

Expand Down Expand Up @@ -29,11 +30,11 @@ function ParsedLink({ children, sect, href, id }) {
}, [href]);

if (folder && file) {
return <a id={id} href={`/free-programming-books-search/?&sect=${folder}&file=${file}`}>{children}</a>;
return <a id={id} href={`${appContextPath}?sect=${folder}&file=${file}`}>{children}</a>;
} else if (file) {
return <a id={id} href={`/free-programming-books-search/?file=${file}`}>{children}</a>;
return <a id={id} href={`${appContextPath}?file=${file}`}>{children}</a>;
} else { // Go to the homepage when there's a bad relative URL
return <a id={id} href={`/free-programming-books-search/`}>{children}</a>
return <a id={id} href={`${appContextPath}`}>{children}</a>
}
}

Expand Down