-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: about thorium hyperlink now target external website instead of open
and read an about thorium publication (Fixes #2622)
- Loading branch information
Showing
1 changed file
with
106 additions
and
106 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 |
---|---|---|
|
@@ -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"; | ||
|
@@ -53,7 +53,7 @@ interface IState { | |
|
||
class AboutThoriumButton extends React.Component<IProps, IState> { | ||
|
||
private manifestView: PublicationView; | ||
// private manifestView: PublicationView; | ||
|
||
constructor(props: IProps) { | ||
super(props); | ||
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
panaC
Author
Member
|
||
}} | ||
tabIndex={0}>{__("catalog.about.title", { appName: capitalizedAppName })}</a> | ||
</div> | ||
|
@@ -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) => { | ||
|
@@ -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)); | ||
// }, | ||
}; | ||
}; | ||
|
||
|
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.