Skip to content

Commit 578d479

Browse files
Add notice for invalid/illegal fonts detected in harvesting (BL-15003)
1 parent 1b753c7 commit 578d479

5 files changed

Lines changed: 103 additions & 50 deletions

File tree

src/components/BookDetail/HarvesterProblemNotice.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@ import React from "react";
22
import { Book } from "../../model/Book";
33
import { MissingFontNotice } from "./MissingFontNotice";
44
import { HarvesterFailedNotice } from "./HarvesterFailedNotice";
5+
import { InvalidFontNotice } from "./InvalidFontNotice";
56

67
export const HarvesterProblemNotice: React.FunctionComponent<{ book: Book }> = (
78
props
89
) => {
9-
if (props.book.getMissingFontNames().length > 0)
10-
return <MissingFontNotice book={props.book} />;
10+
if (
11+
props.book.getMissingFontNames().length > 0 ||
12+
props.book.getInvalidFontNames().length > 0
13+
) {
14+
return (
15+
<>
16+
<MissingFontNotice book={props.book} />
17+
<InvalidFontNotice book={props.book} />
18+
</>
19+
);
20+
}
1121

1222
if (props.book.harvestState === "Failed") return <HarvesterFailedNotice />;
1323

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React, { ReactElement, useEffect, useState } from "react";
2+
import { Book } from "../../model/Book";
3+
import { BlorgLink } from "../BlorgLink";
4+
import { useIntl } from "react-intl";
5+
import { BookProblemNotice } from "./BookProblemNotice";
6+
7+
export const InvalidFontNotice: React.FunctionComponent<{ book: Book }> = (
8+
props
9+
) => {
10+
const l10n = useIntl();
11+
const [names, setNames] = useState<string[]>([]);
12+
useEffect(() => {
13+
setNames(props.book.getInvalidFontNames());
14+
}, [props.book]);
15+
if (!names || names.length === 0) {
16+
return null;
17+
}
18+
19+
const listOfNames = names.join(", ");
20+
21+
return (
22+
<BookProblemNotice>
23+
{l10n.formatMessage({
24+
id: "book.invalidFontsNotice",
25+
defaultMessage:
26+
"We cannot fully present this book because it uses one or more fonts that are not known to be free and open-licensed. Therefore, the PDF and source files are all we are allowed to distribute. Please try to replace these fonts with ones that have open licenses:",
27+
})}{" "}
28+
{listOfNames}
29+
{"."}
30+
</BookProblemNotice>
31+
);
32+
};
Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
1-
import React, { ReactElement, useEffect, useState } from "react";
2-
import { Book } from "../../model/Book";
3-
import { BlorgLink } from "../BlorgLink";
4-
import { useIntl } from "react-intl";
5-
import { BookProblemNotice } from "./BookProblemNotice";
6-
7-
export const MissingFontNotice: React.FunctionComponent<{ book: Book }> = (
8-
props
9-
) => {
10-
const l10n = useIntl();
11-
const [links, setLinks] = useState<ReactElement[]>([]);
12-
13-
useEffect(() => {
14-
const missingFontNames = props.book.getMissingFontNames();
15-
setLinks(
16-
missingFontNames.map((fontName) => (
17-
<BlorgLink
18-
key={fontName}
19-
alwaysnewtab={true}
20-
color="primary"
21-
href={`https://docs.google.com/forms/d/e/1FAIpQLSeo_lwdTU0JY4Nw1zlo1LCceXkLBWcATfWItnS7FqX5Aa3NUg/viewform?usp=pp_url&entry.1604864976=${window.location.href}&entry.1767307754=${fontName}`}
22-
>
23-
{fontName}
24-
</BlorgLink>
25-
))
26-
);
27-
}, [props.book]);
28-
29-
if (!links || links.length === 0) {
30-
return null;
31-
}
32-
33-
const listOfLinks = links.reduce(
34-
(prev: JSX.Element, curr: JSX.Element): any => [prev, ", ", curr]
35-
);
36-
37-
return (
38-
<BookProblemNotice>
39-
{l10n.formatMessage({
40-
id: "book.missingFontsNotice",
41-
defaultMessage:
42-
"We cannot fully present this book because it uses one or more fonts that BloomLibrary.org does not have. Please help us to find each font by clicking on its name and answering some questions: ",
43-
})}
44-
&nbsp;{listOfLinks}
45-
{"."}
46-
</BookProblemNotice>
47-
);
48-
};
1+
import React, { ReactElement, useEffect, useState } from "react";
2+
import { Book } from "../../model/Book";
3+
import { BlorgLink } from "../BlorgLink";
4+
import { useIntl } from "react-intl";
5+
import { BookProblemNotice } from "./BookProblemNotice";
6+
7+
export const MissingFontNotice: React.FunctionComponent<{ book: Book }> = (
8+
props
9+
) => {
10+
const l10n = useIntl();
11+
const [links, setLinks] = useState<ReactElement[]>([]);
12+
13+
useEffect(() => {
14+
const missingFontNames = props.book.getMissingFontNames();
15+
setLinks(
16+
missingFontNames.map((fontName) => (
17+
<BlorgLink
18+
key={fontName}
19+
alwaysnewtab={true}
20+
color="primary"
21+
href={`https://docs.google.com/forms/d/e/1FAIpQLSeo_lwdTU0JY4Nw1zlo1LCceXkLBWcATfWItnS7FqX5Aa3NUg/viewform?usp=pp_url&entry.1604864976=${window.location.href}&entry.1767307754=${fontName}`}
22+
>
23+
{fontName}
24+
</BlorgLink>
25+
))
26+
);
27+
}, [props.book]);
28+
29+
if (!links || links.length === 0) {
30+
return null;
31+
}
32+
33+
const listOfLinks = links.reduce(
34+
(prev: JSX.Element, curr: JSX.Element): any => [prev, ", ", curr]
35+
);
36+
37+
return (
38+
<BookProblemNotice>
39+
{l10n.formatMessage({
40+
id: "book.missingFontsNotice",
41+
defaultMessage:
42+
"We cannot fully present this book because it uses one or more fonts that BloomLibrary.org does not have. Please help us to find each font by clicking on its name and answering some questions: ",
43+
})}{" "}
44+
{listOfLinks}
45+
{"."}
46+
</BookProblemNotice>
47+
);
48+
};

src/model/Book.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ export class Book {
155155
.map((entry) => entry.split(fixedMarker)[1].trim());
156156
}
157157

158+
public getInvalidFontNames(): string[] {
159+
const fixedMarker = "InvalidFont - ";
160+
return this.harvestLog
161+
.filter((entry) => entry.indexOf(fixedMarker) >= 0)
162+
.map((entry) => entry.split(fixedMarker)[1].trim());
163+
}
164+
158165
public getBestLevel(): string | undefined {
159166
if (this.level) return this.level;
160167
return this.getTagValue("computedLevel");

src/translations/BloomLibrary.org/Code Strings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@
284284
"message": "You have permission to modify this book",
285285
"description": ""
286286
},
287+
"book.invalidFontsNotice": {
288+
"message": "We cannot fully present this book because it uses one or more fonts that are not known to be free and open-licensed. Therefore, the PDF and source files are all we are allowed to distribute. Please try to replace these fonts with ones that have open licenses:",
289+
"description": ""
290+
},
287291
"book.metadata.level": {
288292
"description": "",
289293
"message": "Level {levelNumber}"

0 commit comments

Comments
 (0)