Skip to content

Commit

Permalink
fix: about thorium hyperlink now target external website instead of open
Browse files Browse the repository at this point in the history
and read an about thorium publication (Fixes #2622)
  • Loading branch information
panaC committed Oct 28, 2024
1 parent babb90a commit 26c3366
Showing 1 changed file with 106 additions and 106 deletions.
212 changes: 106 additions & 106 deletions src/renderer/library/components/catalog/AboutThoriumButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ import * as stylesFooter from "readium-desktop/renderer/assets/styles/components
import * as stylesGlobal from "readium-desktop/renderer/assets/styles/global.scss";

import { shell } from "electron";
import { existsSync, promises } from "fs";
import * as path from "path";
// import { existsSync, promises } from "fs";
// import * as path from "path";
import * as React from "react";
import { connect } from "react-redux";
import { ABOUT_BOOK_TITLE_PREFIX } from "readium-desktop/common/constant";
import { readerActions } from "readium-desktop/common/redux/actions";
import { PublicationView } from "readium-desktop/common/views/publication";
// import { ABOUT_BOOK_TITLE_PREFIX } from "readium-desktop/common/constant";
// import { readerActions } from "readium-desktop/common/redux/actions";
// import { PublicationView } from "readium-desktop/common/views/publication";
import { _APP_NAME, _APP_VERSION, _PACKAGING } from "readium-desktop/preprocessor-directives";
import {
TranslatorProps, withTranslator,
} from "readium-desktop/renderer/common/components/hoc/translator";
import { TDispatch } from "readium-desktop/typings/redux";
import { findMimeTypeWithExtension, mimeTypes } from "readium-desktop/utils/mimeTypes";
// import { findMimeTypeWithExtension, mimeTypes } from "readium-desktop/utils/mimeTypes";

import { TaJsonSerialize } from "@r2-lcp-js/serializable";
import { Metadata } from "@r2-shared-js/models/metadata";
import { Publication as R2Publication } from "@r2-shared-js/models/publication";
import { Link } from "@r2-shared-js/models/publication-link";
// import { TaJsonSerialize } from "@r2-lcp-js/serializable";
// import { Metadata } from "@r2-shared-js/models/metadata";
// import { Publication as R2Publication } from "@r2-shared-js/models/publication";
// import { Link } from "@r2-shared-js/models/publication-link";

import { apiAction } from "../../apiAction";
// import { apiAction } from "../../apiAction";
import { ILibraryRootState } from "readium-desktop/common/redux/states/renderer/libraryRootState";
import * as EdrlabLogo from "readium-desktop/renderer/assets/icons/logo_edrlab.svg";
import SVG from "readium-desktop/renderer/common/components/SVG";
Expand All @@ -53,7 +53,7 @@ interface IState {

class AboutThoriumButton extends React.Component<IProps, IState> {

private manifestView: PublicationView;
// private manifestView: PublicationView;

constructor(props: IProps) {
super(props);
Expand Down Expand Up @@ -102,9 +102,9 @@ class AboutThoriumButton extends React.Component<IProps, IState> {
<div className={stylesFooter.footer_about}>
<div>
<p>{`v${_APP_VERSION}`}</p>
<a href="" onClick={(ev) => {
<a href="" onClick={async (ev) => {
ev.preventDefault(); // necessary because href="", CSS must also ensure hyperlink visited style
this.about();
await shell.openExternal("https://thorium.edrlab.org/en/about/"); // TODO: not link to the english thorium hyperlink

This comment has been minimized.

Copy link
@llemeurfr

llemeurfr Oct 29, 2024

Contributor

I don't see how to have accept-language used unless we create a cloud function that redirects the user to a specific URL. Better letting this as-is = considering that English is the entry point, and users will change the local from the menu.

This comment has been minimized.

Copy link
@panaC

panaC Oct 29, 2024

Author Member

thorium.edrlab.org should redirect to the user locale in regards to the web api navigator language. it should be https://thorium.edrlab.org/about/ I think

This comment has been minimized.

Copy link
@llemeurfr

llemeurfr Oct 29, 2024

Contributor

this is a static web site powered by Hugo and hosted by Github. I don't think redirect is feasible without middleware.

}}
tabIndex={0}>{__("catalog.about.title", { appName: capitalizedAppName })}</a>
</div>
Expand All @@ -114,94 +114,94 @@ class AboutThoriumButton extends React.Component<IProps, IState> {
);
}

private about = async () => {
const { locale } = this.props;
const infoFolderRelativePath = "assets/md/information/"; // final / is important
const imagesFolder = "images";

let aboutLocale = locale.toLowerCase();

const setTitle = (l: string) => `${ABOUT_BOOK_TITLE_PREFIX}${_APP_VERSION}${l}`;
try {

let title = setTitle(aboutLocale);

let [pubView] = await apiAction("publication/searchEqTitle", title);
if (pubView) {
console.log("pubView already exist no need to generate a new one");
console.log(pubView);

this.manifestView = pubView;

return; // see finally {} below
}
console.log("pubView not found, need to generate a new one: ", title);

let folderPath = path.join((global as any).__dirname, infoFolderRelativePath);
if (_PACKAGING === "0") {
folderPath = path.join(process.cwd(), "dist", infoFolderRelativePath);
}

let htmlFile = `${aboutLocale}.xhtml`;
{
const filePath = path.join(folderPath, `${aboutLocale}.xhtml`);

if (!existsSync(filePath)) {
console.log("about XHTML does not exist (english fallback) ", filePath);
aboutLocale = "en";
}
htmlFile = `${aboutLocale}.xhtml`;
title = setTitle(aboutLocale);
}

[pubView] = await apiAction("publication/searchEqTitle", title);
if (pubView) {
console.log("pubView already exist no need to generate a new one");
console.log(pubView);

this.manifestView = pubView;

return; // see finally {} below
}
console.log("pubView again not found, need to generate a new one: ", title);

const publication = new R2Publication();
publication.Context = ["https://readium.org/webpub-manifest/context.jsonld"];
publication.Metadata = new Metadata();
publication.Metadata.Title = title;

const link = new Link();
link.Href = htmlFile;
link.TypeLink = mimeTypes.xhtml;
link.Title = aboutLocale;
publication.Spine = [link];

const imgPath = path.join(folderPath, imagesFolder);
const imgArray = await promises.readdir(imgPath);
publication.Resources = imgArray.map((i) => {
const l = new Link();
l.Href = `${imagesFolder}/${i}`; // path.join() backslash on Windows
l.TypeLink = findMimeTypeWithExtension(path.extname(l.Href));

return l;
});

const publicationSerialize = TaJsonSerialize(publication);
const publicationStr = JSON.stringify(publicationSerialize);

this.manifestView = await apiAction("publication/importFromString",
publicationStr,
"file://" + folderPath.replace(/\\/g, "/"));

} catch (e) {
console.log("error to import about", aboutLocale, e);

} finally {
if (this.manifestView) {
this.props.openReader(this.manifestView);
}
}
};
// private about = async () => {
// const { locale } = this.props;
// const infoFolderRelativePath = "assets/md/information/"; // final / is important
// const imagesFolder = "images";

// let aboutLocale = locale.toLowerCase();

// const setTitle = (l: string) => `${ABOUT_BOOK_TITLE_PREFIX}${_APP_VERSION}${l}`;
// try {

// let title = setTitle(aboutLocale);

// let [pubView] = await apiAction("publication/searchEqTitle", title);
// if (pubView) {
// console.log("pubView already exist no need to generate a new one");
// console.log(pubView);

// this.manifestView = pubView;

// return; // see finally {} below
// }
// console.log("pubView not found, need to generate a new one: ", title);

// let folderPath = path.join((global as any).__dirname, infoFolderRelativePath);
// if (_PACKAGING === "0") {
// folderPath = path.join(process.cwd(), "dist", infoFolderRelativePath);
// }

// let htmlFile = `${aboutLocale}.xhtml`;
// {
// const filePath = path.join(folderPath, `${aboutLocale}.xhtml`);

// if (!existsSync(filePath)) {
// console.log("about XHTML does not exist (english fallback) ", filePath);
// aboutLocale = "en";
// }
// htmlFile = `${aboutLocale}.xhtml`;
// title = setTitle(aboutLocale);
// }

// [pubView] = await apiAction("publication/searchEqTitle", title);
// if (pubView) {
// console.log("pubView already exist no need to generate a new one");
// console.log(pubView);

// this.manifestView = pubView;

// return; // see finally {} below
// }
// console.log("pubView again not found, need to generate a new one: ", title);

// const publication = new R2Publication();
// publication.Context = ["https://readium.org/webpub-manifest/context.jsonld"];
// publication.Metadata = new Metadata();
// publication.Metadata.Title = title;

// const link = new Link();
// link.Href = htmlFile;
// link.TypeLink = mimeTypes.xhtml;
// link.Title = aboutLocale;
// publication.Spine = [link];

// const imgPath = path.join(folderPath, imagesFolder);
// const imgArray = await promises.readdir(imgPath);
// publication.Resources = imgArray.map((i) => {
// const l = new Link();
// l.Href = `${imagesFolder}/${i}`; // path.join() backslash on Windows
// l.TypeLink = findMimeTypeWithExtension(path.extname(l.Href));

// return l;
// });

// const publicationSerialize = TaJsonSerialize(publication);
// const publicationStr = JSON.stringify(publicationSerialize);

// this.manifestView = await apiAction("publication/importFromString",
// publicationStr,
// "file://" + folderPath.replace(/\\/g, "/"));

// } catch (e) {
// console.log("error to import about", aboutLocale, e);

// } finally {
// if (this.manifestView) {
// this.props.openReader(this.manifestView);
// }
// }
// };
}

const mapStateToProps = (state: ILibraryRootState, _props: IBaseProps) => {
Expand All @@ -214,11 +214,11 @@ const mapStateToProps = (state: ILibraryRootState, _props: IBaseProps) => {
};
};

const mapDispatchToProps = (dispatch: TDispatch, _props: IBaseProps) => {
const mapDispatchToProps = (__dispatch: TDispatch, _props: IBaseProps) => {
return {
openReader: (publicationView: PublicationView) => {
dispatch(readerActions.openRequest.build(publicationView.identifier));
},
// openReader: (publicationView: PublicationView) => {
// dispatch(readerActions.openRequest.build(publicationView.identifier));
// },
};
};

Expand Down

0 comments on commit 26c3366

Please sign in to comment.