Skip to content

Commit

Permalink
Merge from develop
Browse files Browse the repository at this point in the history
  • Loading branch information
zotya committed Mar 14, 2023
2 parents eefe941 + 0cbdd17 commit 3478d37
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 6 deletions.
20 changes: 15 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,28 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

### [1.0.18](https://github.com/eea/volto-datahub/compare/1.0.17...1.0.18) - 13 March 2023

#### :hammer_and_wrench: Others

- lint [Zoltan Szabo - [`3d9c842`](https://github.com/eea/volto-datahub/commit/3d9c8428fac3aa66cba164639926745b81434b52)]
- Remove console.logs [Zoltan Szabo - [`09e19bf`](https://github.com/eea/volto-datahub/commit/09e19bf7656b3a11c5f967b0ff45d05ca8b3bcd5)]
- set lastmod in sitemap [Zoltan Szabo - [`bb2819c`](https://github.com/eea/volto-datahub/commit/bb2819c41eed63a23532cba01eeedd7c3f8b7217)]
- Refs #250008; add datahub sitemap [Tiberiu Ichim - [`c9f9996`](https://github.com/eea/volto-datahub/commit/c9f9996ba71b49932a52b21aeb6b7cfcb80a60d2)]
### [1.0.17](https://github.com/eea/volto-datahub/compare/1.0.16...1.0.17) - 10 March 2023

#### :hammer_and_wrench: Others

- test(Jenkinsfile): Use latest stable volto for testing [Zoltan Szabo - [`7aed7a1`](https://github.com/eea/volto-datahub/commit/7aed7a124289f3b39b479fda1bbedd72de88d95b)]
- Move labels inside <a> [kreafox - [`4273ece`](https://github.com/eea/volto-datahub/commit/4273ece5870b6661b1a66da91f6678923649a3cb)]
- updates on archived items [Zoltan Szabo - [`627225d`](https://github.com/eea/volto-datahub/commit/627225d726ef48cfbcebddbf574abbe46c2c844d)]
### [1.0.16](https://github.com/eea/volto-datahub/compare/1.0.15...1.0.16) - 6 March 2023

#### :hammer_and_wrench: Others

- added utils.js [Zoltan Szabo - [`fdb33c3`](https://github.com/eea/volto-datahub/commit/fdb33c37e1af2fe071dbe8f4f5dcd2b82932edc8)]
- Show 'Obsolete' info in the metadata section in the banner [Zoltan Szabo - [`fddfd2a`](https://github.com/eea/volto-datahub/commit/fddfd2aea63d1a1d1567c163ab29dd7119781117)]
- Show 'More information' section only if it's not empty [Zoltan Szabo - [`612f035`](https://github.com/eea/volto-datahub/commit/612f03509c6adf143631ae6dee5ca2bd48a501c3)]
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`b9100f6`](https://github.com/eea/volto-datahub/commit/b9100f6b2b2e9e9a26b9c11708c8fda94137cecc)]
### [1.0.15](https://github.com/eea/volto-datahub/compare/1.0.14...1.0.15) - 1 March 2023

### [1.0.14](https://github.com/eea/volto-datahub/compare/1.0.13...1.0.14) - 1 March 2023
Expand Down Expand Up @@ -104,11 +118,9 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
#### :hammer_and_wrench: Others

- Fix eslintrc: add @eeacms/search [kreafox - [`465816f`](https://github.com/eea/volto-datahub/commit/465816feb8f58095ab4b5b3168cd29ebede3a10c)]
- Use latest Volto before yarn 3 [Tiberiu Ichim - [`69f5859`](https://github.com/eea/volto-datahub/commit/69f585980fd9a38ff99d0c7875704671857720f7)]
- Reorder sections on landing page [kreafox - [`46fac8d`](https://github.com/eea/volto-datahub/commit/46fac8d821cf93fe1b2c380380719de130c3f1cb)]
- Fix project eslintrc [kreafox - [`5baa150`](https://github.com/eea/volto-datahub/commit/5baa1505ec38ed313269f5608c186c6a6a8bbfc4)]
- Open dataset links in new tab [kreafox - [`bbed914`](https://github.com/eea/volto-datahub/commit/bbed914dc2edf6c749d1d73d93a423bc642e680c)]
- Add Sonarqube tag using circularity-frontend addons list [EEA Jenkins - [`380a2a9`](https://github.com/eea/volto-datahub/commit/380a2a9625c6f799df7a7c343fad3f3b3d959f96)]
## [1.0.0](https://github.com/eea/volto-datahub/compare/0.1.12...1.0.0) - 28 October 2022

#### :nail_care: Enhancements
Expand All @@ -133,7 +145,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
#### :hammer_and_wrench: Others

- fixed query for related items [Zoltan Szabo - [`b66faee`](https://github.com/eea/volto-datahub/commit/b66faee1f8a1922cd22b3a36eccc9c7b92e377d4)]
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`158fe1a`](https://github.com/eea/volto-datahub/commit/158fe1a0b1767452e2e51a3e2ef97169589a50e8)]
### [0.1.10](https://github.com/eea/volto-datahub/compare/0.1.9...0.1.10) - 21 September 2022

#### :hammer_and_wrench: Others
Expand Down Expand Up @@ -222,7 +233,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
#### :hammer_and_wrench: Others

- Hide questions & fix landing page [kreafox - [`a1ef303`](https://github.com/eea/volto-datahub/commit/a1ef3033df0e84f3a72dd0f984c8717dff2a771c)]
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`910688e`](https://github.com/eea/volto-datahub/commit/910688e3ddf2f8cda4f941595ae9a6ee0ec0ea3b)]
### [0.1.1](https://github.com/eea/volto-datahub/compare/0.1.0...0.1.1) - 10 June 2022

### [0.1.0](https://github.com/eea/volto-datahub/compare/0.0.1...0.1.0) - 9 June 2022
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eeacms/volto-datahub",
"version": "1.0.16",
"version": "1.0.18",
"description": "@eeacms/volto-datahub: Volto add-on",
"main": "src/index.js",
"author": "European Environment Agency: IDM2 A-Team",
Expand Down
89 changes: 89 additions & 0 deletions src/express-middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { registry } from '@eeacms/search';
import express from 'express';
import buildRequest from '@eeacms/search/lib/search/query';
import superagent from 'superagent';
// import zlib from 'zlib';

const getUrlES = (appName) => {
return (
process.env[`RAZZLE_PROXY_ES_DSN_${appName}`] ||
process.env.RAZZLE_PROXY_ES_DSN ||
'http://localhost:9200/_all'
);
};

function handleSearchRequest(body, params) {
const { urlES } = params;
const url = `${urlES}/_search`;
if (body?.params?.config) {
delete body.params.config;
}

return new Promise((resolve, reject) => {
superagent
.post(url)
.send(body)
.set('accept', 'application/json')
.end((err, resp) => {
if (resp && resp.body) {
return resolve(resp.body);
}
return reject({ error: 'Error' });
});
});
}

function toPublicURL(id) {
return `https://www.eea.europa.eu/en/datahub/datahubitem-view/${id}`;
}

function generateSitemap(appConfig) {
return new Promise((resolve, reject) => {
const body = buildRequest({ filters: [] }, appConfig);
delete body['source'];
delete body['params'];
delete body['runtime_mappings'];
delete body['index'];
body._source = { include: ['about', 'last_modified'] };
body.size = 10000;
const urlES = getUrlES('datahub');
handleSearchRequest(body, { urlES }).then((body) => {
const items = body?.hits?.hits || [];

const urls = items.map(
(item) => ` <url>\n <loc>${toPublicURL(item._id)}</loc>\n
<lastmod>${item._source.last_modified}</lastmod>\n </url>`,
);
const result = `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">\n${urls.join(
'\n',
)}\n</urlset>`;

// zlib.gzip(Buffer.from(result, 'utf8'), (_err, buffer) => {
// resolve(buffer);
// });

resolve(result);
});
});
}

function sitemap(req, res, next) {
const appConfig = registry.searchui['datahub'];

generateSitemap(appConfig)
.then((body) => res.send(body))
.catch((body) => {
res.send({ error: body });
});
}

export default function makeMiddlewares(config) {
const middleware = express.Router();
// middleware.use(express.json({ limit: config.settings.maxResponseSize }));
middleware.use(express.urlencoded({ extended: true }));

middleware.all('**/datahub/sitemap-data.xml', sitemap);
middleware.id = 'datahub-sitemap';

return middleware;
}
10 changes: 10 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ const applyConfig = (config) => {
...(config.addonRoutes || []),
];
config.addonReducers.datahub_results = datahub_results;

if (__SERVER__) {
const makeMiddlewares = require('./express-middleware').default;

config.settings.expressMiddleware = [
...config.settings.expressMiddleware,
makeMiddlewares(config),
];
}

return config;
};

Expand Down

0 comments on commit 3478d37

Please sign in to comment.