Skip to content

Commit

Permalink
Merge da03451 into ca8418b
Browse files Browse the repository at this point in the history
  • Loading branch information
datakurre committed Apr 30, 2020
2 parents ca8418b + da03451 commit dc792bf
Show file tree
Hide file tree
Showing 16 changed files with 5,333 additions and 3,594 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
node_js:
- 8.16.0
- 10.15.3
- 10
- 12
cache:
pip: true
yarn: true
Expand Down
42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,32 @@
"author": "Ajay NS, Asko Soukka, Andrea Cecchi, Timo Stollenwerk, Victor Fernandez de Alba",
"license": "MIT",
"dependencies": {
"axios": "^0.19.0",
"axios-retry": "^3.1.2",
"gatsby": "^2.15.1",
"gatsby-source-filesystem": "^2.1.18",
"react": "^16.9.0",
"axios": "^0.19.2",
"axios-retry": "^3.1.8",
"gatsby": "^2.21.6",
"gatsby-source-filesystem": "^2.3.0",
"react": "^16.13.1",
"react-html-parser": "^2.0.2",
"react-serialize": "^0.2.0"
},
"devDependencies": {
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-object-rest-spread": "^7.5.5",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/preset-react": "^7.0.0",
"@babel/runtime": "^7.5.5",
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.6",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-object-rest-spread": "^7.9.6",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.9.6",
"@babel/preset-env": "^7.9.6",
"@babel/preset-react": "^7.9.4",
"@babel/runtime": "^7.9.6",
"babel-core": "7.0.0-bridge.0",
"coveralls": "^3.0.6",
"cross-env": "^5.2.0",
"jest": "^24.9.0",
"marked": "^0.7.0",
"nodemon": "^1.19.1",
"prettier": "^1.18.2",
"yalc": "^1.0.0-pre.34"
"coveralls": "^3.1.0",
"cross-env": "^7.0.2",
"jest": "^25.5.2",
"marked": "^1.0.0",
"nodemon": "^2.0.3",
"prettier": "^2.0.5",
"yalc": "^1.0.0-pre.35"
},
"resolutions": {
"babel-core": "7.0.0-bridge.0"
Expand Down
5 changes: 4 additions & 1 deletion src/__tests__/utils.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,10 @@ test('parseHTMLtoReact transforms relative links', async () => {
},
]);
expect(backlinks).toEqual(
new Map([['/foobar/', ['/index/']], ['/foo/bar.png/', ['/index/']]])
new Map([
['/foobar/', ['/index/']],
['/foo/bar.png/', ['/index/']],
])
);
});

Expand Down
32 changes: 18 additions & 14 deletions src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ exports.sourceNodes = async (
} else {
// Iterating all nodes seem to be common way to list cached nodes
const nodesById = getNodes()
.filter(n => n.internal.owner === `gatsby-source-plone`)
.filter((n) => n.internal.owner === `gatsby-source-plone`)
.reduce((map, node) => map.set(node.id, node), new Map());

const updateNodes = new Set();
Expand Down Expand Up @@ -185,27 +185,31 @@ exports.sourceNodes = async (
}
if (!item._id.startsWith(dirtyBreadcrumbs)) {
reporter.info(
`Touching node – ${item._id.replace(baseUrl, '') ||
'/'}/@breadcrumbs`
`Touching node – ${
item._id.replace(baseUrl, '') || '/'
}/@breadcrumbs`
);
touchNode({ nodeId: `${item._id}/@breadcrumbs` });
} else {
reporter.info(
`Creating node – ${item._id.replace(baseUrl, '') ||
'/'}/@breadcrumbs`
`Creating node – ${
item._id.replace(baseUrl, '') || '/'
}/@breadcrumbs`
);
createNode(await fetchPloneBreadcrumbsNode(item._id, token, baseUrl));
}
if (!item._id.startsWith(dirtyNavigation)) {
reporter.info(
`Touching node – ${item._id.replace(baseUrl, '') ||
'/'}/@navigation`
`Touching node – ${
item._id.replace(baseUrl, '') || '/'
}/@navigation`
);
touchNode({ nodeId: `${item._id}/@navigation` });
} else {
reporter.info(
`Creating node – ${item._id.replace(baseUrl, '') ||
'/'}/@navigation`
`Creating node – ${
item._id.replace(baseUrl, '') || '/'
}/@navigation`
);
createNode(await fetchPloneNavigationNode(item._id, token, baseUrl));
}
Expand All @@ -215,7 +219,7 @@ exports.sourceNodes = async (
reporter.info('Setting plugin status');
reporter.info(JSON.stringify(newState));

const webSocketStart = function(reconnectionDelay = 1) {
const webSocketStart = function (reconnectionDelay = 1) {
let ws = new WebSocket(baseUrl.replace(/(http)(s)?\:\/\//, 'ws$2://'));
let timerId = null;
let count = 0;
Expand All @@ -229,7 +233,7 @@ exports.sourceNodes = async (
count++;
}, 60000);

ws.onmessage = async msg => {
ws.onmessage = async (msg) => {
let data = JSON.parse(msg.data);
if (data['created']) {
await createWebsocketEvent(
Expand Down Expand Up @@ -312,11 +316,11 @@ exports.sourceNodes = async (
);
}
};
ws.onclose = function() {
ws.onclose = function () {
reconnectingWebSocket(ws, reconnectionDelay);
clearInterval(intervalId);
};
ws.onerror = function(err) {
ws.onerror = function (err) {
reporter.error(err.message);
clearInterval(intervalId);
};
Expand All @@ -325,7 +329,7 @@ exports.sourceNodes = async (
});
};

const reconnectingWebSocket = function(ws, reconnectionDelay) {
const reconnectingWebSocket = function (ws, reconnectionDelay) {
reconnectionDelay = Math.min(60, reconnectionDelay * (2 - Math.random()));
setTimeout(() => {
if (ws.readyState == 3) {
Expand Down
2 changes: 1 addition & 1 deletion src/util/createWebsocketEvent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ploneNodeGenerator } from './ploneNodeGenerator';

export const createWebsocketEvent = async function(
export const createWebsocketEvent = async function (
data,
token,
baseUrl,
Expand Down
2 changes: 1 addition & 1 deletion src/util/deleteWebSocketEvent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ploneNodeGenerator } from './ploneNodeGenerator';

export const deleteWebSocketEvent = async function(
export const deleteWebSocketEvent = async function (
data,
getNode,
deleteNode,
Expand Down
2 changes: 1 addition & 1 deletion src/util/fetchUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { serializeParams } from './serializeParams';

axiosRetry(axios, {
retries: 3,
retryDelay: retryCount => {
retryDelay: (retryCount) => {
return retryCount * 1000 + retryCount * 1000 * Math.random();
},
});
Expand Down
18 changes: 5 additions & 13 deletions src/util/helper.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import crypto from 'crypto';

// Create content digest (hash)
export const createContentDigest = data =>
crypto
.createHash('md5')
.update(JSON.stringify(data))
.digest('hex');
export const createContentDigest = (data) =>
crypto.createHash('md5').update(JSON.stringify(data)).digest('hex');

// Get URL without query parameters
export const urlWithoutParameters = url => {
export const urlWithoutParameters = (url) => {
return url.split('?')[0];
};

// Return parent id for Plone REST API content object id
export const parentId = id =>
id.match(/\//g).length >= 3
? id
.split('/')
.slice(0, -1)
.join('/')
: id;
export const parentId = (id) =>
id.match(/\//g).length >= 3 ? id.split('/').slice(0, -1).join('/') : id;
4 changes: 2 additions & 2 deletions src/util/modifiedWebSocketEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fetchPloneBreadcrumbsNode } from './fetchPloneBreadcrumbsNode';
import { fetchPloneNavigationNode } from './fetchPloneNavigationNode';
import { normalizeData } from './normalizeData';

export const modifiedWebSocketEvent = async function(
export const modifiedWebSocketEvent = async function (
data,
createNode,
getNode,
Expand Down Expand Up @@ -58,7 +58,7 @@ export const modifiedWebSocketEvent = async function(
);
};

const childItemsForUrl = async function(
const childItemsForUrl = async function (
urlChild,
token,
baseUrl,
Expand Down
14 changes: 7 additions & 7 deletions src/util/normalizeData.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { urlWithoutParameters } from './helper';
import { normalizePath } from './normalizePath';

// Normalize Plone JSON to be usable as such in GatsbyJS
export const normalizeData = function(data, baseUrl) {
export const normalizeData = function (data, baseUrl) {
// - Adds '@id' for plone.restapi < 1.0b1 results from 'url'
if (!data['@id'] && data.url) {
data['@id'] = data.url;
Expand All @@ -28,19 +28,19 @@ export const normalizeData = function(data, baseUrl) {
}
delete data[key];
} else if (key === 'items') {
data[key] = (value || []).map(item => normalizeData(item, baseUrl));
data[key] = (value || []).map((item) => normalizeData(item, baseUrl));
data.nodes___NODE = data[key]
.filter(
item => item['_id'].startsWith(baseUrl) && !item['_id'].match('@')
(item) => item['_id'].startsWith(baseUrl) && !item['_id'].match('@')
)
.map(item => item['_id']);
.map((item) => item['_id']);
} else if (key === 'relatedItems') {
data[key] = (value || []).map(item => normalizeData(item, baseUrl));
data[key] = (value || []).map((item) => normalizeData(item, baseUrl));
data.relatedNodes___NODE = data[key]
.filter(
item => item['_id'].startsWith(baseUrl) && !item['_id'].match('@')
(item) => item['_id'].startsWith(baseUrl) && !item['_id'].match('@')
)
.map(item => item['_id']);
.map((item) => item['_id']);
} else if (key === '@id') {
if (value.match(/\/view$/)) {
// @navigation may contain @id values with reserved /view suffix
Expand Down
2 changes: 1 addition & 1 deletion src/util/normalizePath.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Normalize path
export const normalizePath = path => {
export const normalizePath = (path) => {
path = path ? path.replace(/^\/*/, '/').replace(/\/*$/, '/') : '/';
if (path.match(/\/view\/$/)) {
path = path.substr(0, path.length - 'view/'.length);
Expand Down
4 changes: 2 additions & 2 deletions src/util/normalizeType.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Camelize
export const normalizeType = type => {
export const normalizeType = (type) => {
type = type
.replace(/(?:^\w|[A-Z]|\b\w)/g, function(letter) {
.replace(/(?:^\w|[A-Z]|\b\w)/g, function (letter) {
return letter.toUpperCase();
})
.replace(/[\s\.]+/g, '');
Expand Down
2 changes: 1 addition & 1 deletion src/util/ploneNodeGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { makeContentNode } from './makeContentNode';
import { makeNavigationNode } from './makeNavigationNode';
import { fetchPlone } from './fetchPlone';

export const ploneNodeGenerator = async function*(
export const ploneNodeGenerator = async function* (
id,
token,
baseUrl,
Expand Down
4 changes: 2 additions & 2 deletions src/util/serializeParams.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const serializeParams = params => {
export const serializeParams = (params) => {
let parts = [];

Object.entries(params).forEach(([key, val]) => {
Expand All @@ -15,7 +15,7 @@ export const serializeParams = params => {
val = [val];
}

val.forEach(v => {
val.forEach((v) => {
if (typeof v.getMonth === 'function') {
v = v.toISOString();
} else if (typeof v === 'object') {
Expand Down
4 changes: 2 additions & 2 deletions src/util/updatePloneCollection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ploneNodeGenerator } from './ploneNodeGenerator';

export const updatePloneCollection = async function(
export const updatePloneCollection = async function (
getNodes,
token,
baseUrl,
Expand All @@ -11,7 +11,7 @@ export const updatePloneCollection = async function(
) {
reporter.info('we are updating the Plone Collection');
const nodes = getNodes().filter(
n => n.internal.owner === `gatsby-source-plone`
(n) => n.internal.owner === `gatsby-source-plone`
);
const updateNodes = new Set();
for (let item of nodes) {
Expand Down
Loading

0 comments on commit dc792bf

Please sign in to comment.