Skip to content

Commit ed26dbd

Browse files
committed
refactor: simplify Overpass API loader for readibility
1 parent 5e41723 commit ed26dbd

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

eslint.config.js

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export default antfu(
1313
'node/prefer-global/process': ['error', 'always'],
1414
'style/arrow-parens': ['error', 'always'],
1515
'style/brace-style': ['error', '1tbs'],
16-
'style/no-multi-spaces': ['error', { ignoreEOLComments: true }],
1716
'style/operator-linebreak': ['error', 'after', { overrides: { '?': 'before', ':': 'before' } }],
1817
'vue/max-attributes-per-line': ['error'],
1918
'vue/attributes-order': ['error', { alphabetical: true }],

loaders/overpass.data.ts

+4-14
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,12 @@ import { defineLoader } from 'vitepress'
88
* @example const geometry = await queryOverpass(['way(1159328965)'])
99
*/
1010
function queryOverpass(objects: string[]): Promise<GeoJSON.GeoJsonObject> {
11-
/* eslint-disable prefer-template --
12-
* string concatenation is more readable across multiple lines
13-
*/
14-
// Build the Overpass API query
15-
const query =
16-
'[out:json];' + // Set the output format to JSON
17-
objects.map((object) => // For each object
18-
`${object};` + // Query the object
19-
'out geom;', // Output the geometry
20-
).join('') // Join the queries
21-
/* eslint-enable prefer-template */
11+
// Query the objects' geometries
12+
const queries = objects.map((object) => `${object};out geom;`)
2213

2314
return fetch('https://overpass-api.de/api/interpreter', {
2415
method: 'POST',
25-
body: `data=${query}`,
16+
body: `data=[out:json];${queries.join('')}`,
2617
})
2718
.then((response) => response.json())
2819
.then(osmToGeoJSON)
@@ -36,8 +27,7 @@ interface OverpassData {
3627
/**
3728
* The geometry of the venue and its buildings.
3829
*/
39-
declare const data: OverpassData
40-
export { data }
30+
export declare const data: OverpassData
4131

4232
export default defineLoader({
4333
async load(): Promise<OverpassData> {

0 commit comments

Comments
 (0)