-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathbuildPlaceJsonLd.ts
72 lines (65 loc) · 2.08 KB
/
buildPlaceJsonLd.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { buildAllezPartFromOsmFeature } from './app/SetDestination'
import getUrl from './app/osm/getUrl'
import { getFetchUrlBase } from './app/serverUrls'
import { buildPlaceMap } from './components/buildPlaceMap'
import fetchOgImage from './components/fetchOgImage'
export default async function buildPlaceJsonLd(osmFeature, step) {
const { tags = {} } = osmFeature
const osmImage = tags.image || (await fetchOgImage(getUrl(tags)))
const { photonFeature } = step
const addressProperties = photonFeature && photonFeature.properties
const url =
getFetchUrlBase() +
'/?allez=' +
encodeURIComponent(buildAllezPartFromOsmFeature(osmFeature))
const image = osmImage || buildPlaceMap(osmFeature.lat, osmFeature.lon)
const result = {
'@context': 'https://schema.org',
'@type': 'Place', //TODO make this more precise with categories.yaml
//TODO read this list of properties to see which we can fill
//https://schema.org/Place
//additionalType: ['http://www.productontology.org/id/G%C3%AEte'], //TODO
//this too if useful
//TODO put all tags not used as additionalProperty https://schema.org/additionalProperty
//
//
image: image ? [image] : undefined,
//TODO duplicate of image ?
...(image
? {
photo: {
'@type': 'ImageObject',
contentUrl: image,
name: tags.name,
},
}
: {}),
name: tags.name,
description: tags.description,
url,
address: {
'@type': 'PostalAddress',
addressLocality: addressProperties.city,
postalCode: addressProperties.postcode,
addressRegion: addressProperties.state,
addressCountry: addressProperties.countrycode,
},
geo: {
'@type': 'GeoCoordinates',
latitude: osmFeature.lat,
longitude: osmFeature.lon,
},
hasMap: 'https://cartes.app/',
telephone: tags['phone'] || tags['contact:phone'] || tags['contact:mobile'],
alternateName: tags['alt_name'],
//TODO
//isAccessibleForFree
//for opening hours we'll need the work of someone else
//openingHoursSpecification
}
return Object.fromEntries(
Object.entries(result)
.map(([k, v]) => v != null && [k, v])
.filter(Boolean)
)
}