Skip to content

Commit

Permalink
Merge branch 'feature/content-parser-2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jacamera committed Aug 12, 2021
2 parents f83e310 + ada8b05 commit faadeb7
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 24 deletions.
26 changes: 26 additions & 0 deletions build/targets/contentParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const
fs = require('fs'),
path = require('path');

const
project = require('../project'),
createBuild = require('../createBuild');

const package = JSON.parse(
fs
.readFileSync('./package.json')
.toString()
);

const build = createBuild({
path: 'common/contentParsing',
webpack: {
entry: path.posix.join(project.srcDir, 'common/contentParsing/parseDocumentContent.ts'),
fileName: `content-parser-${package['it.reallyread'].version.common.contentParser}.js`,
sourceMaps: false,
minify: false,
outputLibrary: 'contentParser'
}
});

module.exports = build;
2 changes: 1 addition & 1 deletion build/targets/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const
.toString()
),
webUrlPattern = config.webServer.protocol + '://' + config.webServer.host + '/*';
manifest.version = package['it.reallyread'].version.extension.package.toString().padEnd(4, '0');
manifest.version = package['it.reallyread'].version.extension;
manifest.content_scripts[0].matches.push(webUrlPattern);
manifest.permissions.push(webUrlPattern);
fs.writeFileSync(
Expand Down
16 changes: 15 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const
extension = require('./build/targets/extension'),
nativeClientReader = require('./build/targets/nativeClient/reader'),
nativeClientShareExtension = require('./build/targets/nativeClient/shareExtension'),
metadataParser = require('./build/targets/metadataParser');
metadataParser = require('./build/targets/metadataParser'),
contentParser = require('./build/targets/contentParser');

/**
* app
Expand Down Expand Up @@ -55,6 +56,16 @@ function buildProdBrowser() {
return client.build(project.env.prod);
}

/**
* contentParser
*/
function cleanDevContentParser() {
return contentParser.clean(project.env.dev);
}
function buildDevContentParser() {
return contentParser.build(project.env.dev);
}

/**
* embed
*/
Expand Down Expand Up @@ -178,6 +189,9 @@ module.exports = {
'build:stage:browser': buildStageBrowser,
'clean:prod:browser': cleanProdBrowser,
'build:prod:browser': buildProdBrowser,
'clean:dev:content-parser': cleanDevContentParser,
'build:dev:content-parser': buildDevContentParser,
'watch:dev:content-parser': contentParser.watch,
'clean:dev:embed': cleanDevEmbed,
'build:dev:embed': buildDevEmbed,
'watch:dev:embed': embed.watch,
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
"app": "1.45.2",
"appPublic": "1.45.2",
"common": {
"contentParser": "2.0.0",
"metadataParser": "1.0.1"
},
"embed": "1.0.1",
"embedIframe": "1.0.0",
"extension": {
"package": "5.0.2",
"contentParser": "1.1.2"
},
"extension": "5.0.2",
"nativeClient": {
"reader": "12.1.2",
"shareExtension": "4.0.3"
Expand Down
9 changes: 5 additions & 4 deletions src/common/PackageVersionInfo.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
export default interface PackageVersionInfo {
app: string,
appPublic: string,
common: {
contentParser: string,
metadataParser: string
},
embed: string,
embedIframe: string,
extension: {
package: string,
contentParser: string
},
extension: string,
nativeClient: {
reader: string,
shareExtension: string
Expand Down
12 changes: 9 additions & 3 deletions src/common/contentParsing/parseDocumentContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function findTraversalPaths(group: TextContainerDepthGroup) {
})
];
for (let i = 1; i <= group.depth && peers.length; i++) {
const
const
containerLineageIndex = group.depth - i,
foundPeers = peers.filter(peer => peer.containerLineage[containerLineageIndex] === member.containerLineage[containerLineageIndex]);
if (foundPeers.length) {
Expand Down Expand Up @@ -483,8 +483,14 @@ function findChildren(parent: Node, depth: number, edge: GraphEdge, searchArea:
);
}

export default function parseDocumentContent(): ParseResult {
const publisherConfig = findPublisherConfig(configs.publishers, window.location.hostname);
export interface ParserParams {
url: {
hostname: string
}
}

export default function parseDocumentContent(params: ParserParams): ParseResult {
const publisherConfig = findPublisherConfig(configs.publishers, params.url.hostname);

let contentSearchRootElement: Element;
if (publisherConfig && publisherConfig.contentSearchRootElementSelector) {
Expand Down
4 changes: 3 additions & 1 deletion src/embed/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ const apiServer = new ApiServer({
function activate(initializationResponse: InitializationActivationResponse) {
// set up the reader
const page = new Page(
parseDocumentContent()
parseDocumentContent({
url: window.location
})
.primaryTextContainers
);
page.setReadState(initializationResponse.userArticle.readState);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import LazyScript from './LazyScript';
import ParseResult from '../../../common/contentParsing/ParseResult';
import { ParserParams } from '../../../common/contentParsing/parseDocumentContent';

declare global {
interface ReaderContentScriptWindow {
contentParser: LazyScript<{
parse: () => ParseResult,
parse: (params: ParserParams) => ParseResult,
prune: (parseResult: ParseResult) => {
contentRoot: HTMLElement,
scrollRoot: HTMLElement
Expand Down
6 changes: 3 additions & 3 deletions src/extension/content-scripts/reader/content-parser/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import parseDocumentContent from "../../../../common/contentParsing/parseDocumentContent";
import parseDocumentContent, { ParserParams } from "../../../../common/contentParsing/parseDocumentContent";
import pruneDocument from "../../../../common/contentParsing/pruneDocument";
import ParseResult from "../../../../common/contentParsing/ParseResult";

window.reallyreadit.readerContentScript.contentParser.set({
parse: () => {
return parseDocumentContent();
parse: (params: ParserParams) => {
return parseDocumentContent(params);
},
prune: (parseResult: ParseResult) => {
return pruneDocument(parseResult);
Expand Down
4 changes: 3 additions & 1 deletion src/extension/content-scripts/reader/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,9 @@ eventPageApi
.get()
.then(
contentParser => {
const contentParseResult = contentParser.parse();
const contentParseResult = contentParser.parse({
url: window.location
});
return {
contentParser,
contentParseResult,
Expand Down
2 changes: 1 addition & 1 deletion src/extension/event-page/ServerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import InstallationResponse from '../../common/models/extension/InstallationResp
import CommentCreationResponse from '../../common/models/social/CommentCreationResponse';

function addCustomHeaders(req: XMLHttpRequest, params: Request) {
req.setRequestHeader('X-Readup-Client', `web/extension@${window.reallyreadit.extension.config.version.extension.package}`);
req.setRequestHeader('X-Readup-Client', `web/extension@${window.reallyreadit.extension.config.version.extension}`);
}
export default class ServerApi {
public static alarms = {
Expand Down
4 changes: 2 additions & 2 deletions src/extension/event-page/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const readerContentScriptApi = new ReaderContentScriptApi({
try {
if (
new SemanticVersion(localStorage.getItem('contentParserVersion'))
.compareTo(new SemanticVersion(window.reallyreadit.extension.config.version.extension.contentParser)) > 0
.compareTo(new SemanticVersion(window.reallyreadit.extension.config.version.common.contentParser)) > 0
) {
console.log(`contentScriptApi.onLoadContentParser (loading content parser from localStorage, tabId: ${tabId})`);
chrome.tabs.executeScript(tabId, { code: localStorage.getItem('contentParserScript') });
Expand Down Expand Up @@ -475,7 +475,7 @@ chrome.alarms.onAlarm.addListener(
if (alarm.name === 'updateContentParser') {
const currentVersion = SemanticVersion.greatest(
...[
window.reallyreadit.extension.config.version.extension.contentParser,
window.reallyreadit.extension.config.version.common.contentParser,
localStorage.getItem('contentParserVersion')
]
.filter(string => !!string)
Expand Down
4 changes: 3 additions & 1 deletion src/native-client/reader/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ function updateDisplayPreference(preference: DisplayPreference | null) {

const
metadataParseResult = parseDocumentMetadata(),
contentParseResult = parseDocumentContent();
contentParseResult = parseDocumentContent({
url: window.location
});

const { contentRoot, scrollRoot } = pruneDocument(contentParseResult);

Expand Down
4 changes: 3 additions & 1 deletion src/native-client/share-extension/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ new WebViewMessagingContext().sendMessage({
type: 'parseResult',
data: createPageParseResult(
parseDocumentMetadata(),
parseDocumentContent()
parseDocumentContent({
url: window.location
})
)
});

0 comments on commit faadeb7

Please sign in to comment.