Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
RobAndrewHurst committed Jun 4, 2020
2 parents 3788fa9 + a7d464b commit 190c50c
Show file tree
Hide file tree
Showing 136 changed files with 21,271 additions and 2,026 deletions.
33 changes: 33 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const markdownIt = require("markdown-it");

module.exports = function (eleventyConfig) {

eleventyConfig.setLibrary("md", markdownIt({
html: true,
breaks: true,
linkify: true
}));

eleventyConfig.addCollection('posts', collection => {

const _collection = collection.getFilteredByGlob('**/*.md').sort((a, b) => {
if ((a.data.orderPath || a.filePathStem) < (b.orderPath || b.filePathStem)) return -1;
else if ((a.data.orderPath || a.filePathStem) > (b.orderPath || b.filePathStem)) return 1;
else return 0;
})

let currentGroup;

_collection.forEach(entry => {
let path = entry.inputPath.split('/');
let group = path[path.length - 2];
entry.data.level = path.length - 3;
if (group !== currentGroup) entry.data.class = '__' + entry.data.level;
currentGroup = group;
entry.data.tag = entry.data.tags && entry.data.tags[0];
})

return _collection;
});

};
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**v3.1.1**
**v3.2.0**

# xyz

Expand Down
32 changes: 21 additions & 11 deletions api/gazetteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ module.exports = async (req, res) => {
const locale = workspace.locales[req.params.locale]

// Return 406 is gazetteer is not found in locale.
if (!locale) return res.send('Help text.')
if (!locale) {
return res.send(`Failed to evaluate 'locale' param.<br><br>
<a href="https://geolytix.github.io/xyz/docs/develop/api/gazetteer/">Gazetteer API</a>`)
}

// Return 406 is gazetteer is not found in locale.
if (!locale.gazetteer) return res.status(400).send(new Error('Gazetteer not defined for locale.'))
Expand Down Expand Up @@ -132,6 +135,8 @@ async function gaz_mapbox(term, gazetteer) {

async function gaz_locale(req, locale) {

const results = [];

// Loop through dataset entries in gazetteer configuration.
for (let dataset of locale.gazetteer.datasets) {

Expand Down Expand Up @@ -172,20 +177,25 @@ async function gaz_locale(req, locale) {
// Get gazetteer results from dataset table.
var rows = await dbs[dataset.dbs || layer && layer.dbs](q, [`${dataset.leading_wildcard ? '%' : ''}${decodeURIComponent(req.params.q)}%`])

if (rows instanceof Error) return { err: 'Error fetching gazetteer results.' }
if (rows instanceof Error) {
console.log({ err: 'Error fetching gazetteer results.' });
continue;
}

// Format JSON array of gazetteer results from rows object.
if (rows.length > 0) return Object.values(rows).map(row => ({
label: row.label,
id: row.id,
table: dataset.table,
layer: dataset.layer,
marker: `${row.lng},${row.lat}`,
source: dataset.source || 'glx'
}))
if(rows.length > 0) {
Object.values(rows).map(row => results.push({
label: row.label,
id: row.id,
table: dataset.table,
layer: dataset.layer,
marker: `${row.lng},${row.lat}`,
source: dataset.source || 'glx'
}));
};

}

// Return empty results array if no results where found in any dataset.return []
return []
return results;
}
10 changes: 8 additions & 2 deletions api/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ module.exports = async (req, res) => {

const format = _format[req.params.format]

if (!format) return res.send('Help text.')
if (!format) {
return res.send(`Failed to evaluate 'format' param.<br><br>
<a href="https://geolytix.github.io/xyz/docs/develop/api/layer/">Layer API</a>`)
}

req.params.layer = req.params.locale && workspace.locales[req.params.locale].layers[req.params.layer]

if (!req.params.layer) return res.send('Help text.')
if (!req.params.layer) {
return res.status().send(`Failed to evaluate 'layer' param.<br><br>
<a href="https://geolytix.github.io/xyz/docs/develop/api/layer/">Layer API</a>`)
}

return format(req, res)
}
10 changes: 8 additions & 2 deletions api/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ module.exports = async (req, res) => {

const method = _method[req.params.method]

if (!method) return res.send('Help text.')
if (!method) {
return res.send(`Failed to evaluate 'method' param.<br><br>
<a href="https://geolytix.github.io/xyz/docs/develop/api/location/">Location API</a>`)
}

req.params.layer = req.params.locale && workspace.locales[req.params.locale].layers[req.params.layer]

if (!req.params.layer) return res.send('Help text.')
if (!req.params.layer) {
return res.status().send(`Failed to evaluate 'layer' param.<br><br>
<a href="https://geolytix.github.io/xyz/docs/develop/api/location/">Location API</a>`)
}

return method(req, res)
}
5 changes: 4 additions & 1 deletion api/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ module.exports = async (req, res) => {

const provider = _provider[req.params.provider]

if (!provider) return res.send('Help text.')
if (!provider) {
return res.send(`Failed to evaluate 'provider' param.<br><br>
<a href="https://geolytix.github.io/xyz/docs/develop/api/provider/">Provider API</a>`)
}

req.body = req.body && await bodyData(req) || null

Expand Down
5 changes: 4 additions & 1 deletion api/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ module.exports = async (req, res) => {

if (!_dbs) return res.status(500).send(`Cannot connect to ${template.dbs || req.params.dbs || req.params.layer.dbs}`)

const rows = await _dbs(q, req.body && req.body.length && [JSON.stringify(req.body)] || req.params.params && req.params.params.split(','))
const rows = await _dbs(
q,
req.body && req.body.length && [JSON.stringify(req.body)] || req.params.params && req.params.params.split(','),
req.params.statement_timeout)

if (rows instanceof Error) return res.status(500).send('Failed to query PostGIS table.')

Expand Down
5 changes: 4 additions & 1 deletion api/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ module.exports = async (req, res) => {

const method = _method[req.params.method]

if (!method) return res.send('Help text.')
if (!method) {
return res.send(`Failed to evaluate 'method' param.<br><br>
<a href="https://geolytix.github.io/xyz/docs/develop/api/user/">User API</a>`)
}

method.access && await auth(req, res, method.access)

Expand Down
5 changes: 4 additions & 1 deletion api/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ module.exports = async (req, res) => {
return res.send('Logged out.')
}

if (access && access !== 'login') return res.send('Help text.')
if (access && access !== 'login') {
return res.send(`Failed to evaluate 'access' param.<br><br>
<a href="https://geolytix.github.io/xyz/docs/develop/api/view/">View API</a>`)
}

await auth(req, res, access)

Expand Down
8 changes: 6 additions & 2 deletions api/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ module.exports = async (req, res) => {

const method = _method[req.params && req.params.method]

if (!method) return res.send('Help text.')
if (!method) {
return res.send(`Failed to evaluate 'method' param.<br><br>
<a href="https://geolytix.github.io/xyz/docs/develop/api/workspace/">Workspace API</a>`)
}

await auth(req, res, method.access)

Expand Down Expand Up @@ -129,5 +132,6 @@ async function get(req, res) {

if (req.params.key === 'locales') return res.send(Object.keys(workspace.locales))

res.send('Help text.')
res.send(`Failed to evaluate 'key' param.<br><br>
<a href="https://geolytix.github.io/xyz/docs/develop/api/workspace/">Workspace API</a>`)
}
Loading

0 comments on commit 190c50c

Please sign in to comment.