Skip to content

Commit

Permalink
readability: infer lang from page, add fallback language option (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasGollenstede committed Aug 2, 2020
1 parent cf38821 commit 0b1dc2f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
11 changes: 9 additions & 2 deletions common/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@
}) => {

const model = {
defaultLanguage: {
title: `Default Book Language`,
description: `Default '<dc:language>' to set if none could be detected.`,
default: 'en',
restrict: { match: (/^[a-z]{2,10}(:?-[A-Z]{2,10})?$/), message: `Must be n ISO language code, e.g. 'en' or 'en-US'`, },
input: { type: 'boolean', },
},
setNavProperty: {
title: `Set 'nav' property`,
title: `Set 'nav' Property`,
description: `Standard compliant when set, but disables the navigation in Sumatra PDF.`,
default: false,
input: { type: 'boolean', },
},
collectStyles: {
title: `Keep style information`,
title: `Keep Style Information`,
description: `If enabled, some style information are extracted, but some readers won't be able to change the font settings when styles are set.
Only applies to <code>overdrive.com</code>, reader mode always removes all styles.`,
default: false,
Expand Down
1 change: 1 addition & 0 deletions content/collect.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
const collect = (await require.async('content/collect/'+ collector));
const contents = (await collect({ styles: options.collectStyles.value, ...params, }));
if (!contents) { return null; }
if (!contents.language) { contents.language = options.defaultLanguage.value; }

const book = new EPub(Object.assign(contents, { markNav: options.setNavProperty.value, }));
(await book.loadResources({ allowErrors: true, }));
Expand Down
2 changes: 1 addition & 1 deletion content/collect/about-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ return ({
}, ],
title,
description: `Offline reader version of ${url}`,
language: null,
language: (new URL(url).hostname.match(/[.](.{2})$/) || [ null, null, ])[1],
creator: [ { name: author, role: 'author', }, ],
resources,
cover: false,
Expand Down
6 changes: 5 additions & 1 deletion content/collect/readability.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ document.querySelector('.reader-title').textContent = parsed.title || '';
document.querySelector('.reader-credits').textContent = parsed.byline || '';
document.querySelector('.container>.content').innerHTML = parsed.content; // this is not a live document, so this should be unproblematic: https://github.com/mozilla/readability/issues/404

return aboutReader({ document, });
const content = (await aboutReader({ document, }));
return {
...content,
language: global.document.documentElement.lang || global.document.body.lang || content.language,
};

}); })(this);

0 comments on commit 0b1dc2f

Please sign in to comment.