transit-departures-widget 2.2.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/app/index.js +22 -0
- package/docs/images/transit-departures-widget-logo.svg +13 -13
- package/lib/file-utils.js +1 -0
- package/lib/transit-departures-widget.js +13 -0
- package/lib/utils.js +38 -9
- package/package.json +6 -6
- package/public/js/transit-departures-widget.js +28 -8
- package/views/widget/widget.pug +5 -6
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.4.0] - 2024-07-03
|
|
9
|
+
|
|
10
|
+
## Updated
|
|
11
|
+
|
|
12
|
+
- Store routes and stops in separate JSON file
|
|
13
|
+
- Dependency updates
|
|
14
|
+
|
|
15
|
+
## Fixed
|
|
16
|
+
|
|
17
|
+
- Copy img folder
|
|
18
|
+
|
|
19
|
+
## [2.3.0] - 2024-04-22
|
|
20
|
+
|
|
21
|
+
## Fixed
|
|
22
|
+
|
|
23
|
+
- Better removing of last stoptime of trip
|
|
24
|
+
|
|
8
25
|
## [2.2.1] - 2024-04-08
|
|
9
26
|
|
|
10
27
|
## Fixed
|
package/app/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import logger from 'morgan'
|
|
|
10
10
|
import {
|
|
11
11
|
setDefaultConfig,
|
|
12
12
|
generateTransitDeparturesWidgetHtml,
|
|
13
|
+
generateTransitDeparturesWidgetJson,
|
|
13
14
|
} from '../lib/utils.js'
|
|
14
15
|
|
|
15
16
|
const { argv } = yargs(process.argv).option('c', {
|
|
@@ -57,6 +58,27 @@ router.get('/', async (request, response, next) => {
|
|
|
57
58
|
}
|
|
58
59
|
})
|
|
59
60
|
|
|
61
|
+
/*
|
|
62
|
+
* Provide data
|
|
63
|
+
*/
|
|
64
|
+
router.get('/data/routes.json', async (request, response, next) => {
|
|
65
|
+
try {
|
|
66
|
+
const { routes } = await generateTransitDeparturesWidgetJson(config)
|
|
67
|
+
response.json(routes)
|
|
68
|
+
} catch (error) {
|
|
69
|
+
next(error)
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
router.get('/data/stops.json', async (request, response, next) => {
|
|
74
|
+
try {
|
|
75
|
+
const { stops } = await generateTransitDeparturesWidgetJson(config)
|
|
76
|
+
response.json(stops)
|
|
77
|
+
} catch (error) {
|
|
78
|
+
next(error)
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
|
|
60
82
|
app.set('views', path.join(fileURLToPath(import.meta.url), '../../views'))
|
|
61
83
|
app.set('view engine', 'pug')
|
|
62
84
|
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
<svg width="
|
|
2
|
-
<path fill-rule="evenodd" clip-rule="evenodd" d="
|
|
3
|
-
<path fill-rule="evenodd" clip-rule="evenodd" d="
|
|
4
|
-
<mask id="
|
|
5
|
-
<path d="
|
|
1
|
+
<svg width="280" height="311" viewBox="0 0 280 311" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M279.142 216.458V95.0263C279.142 82.9559 272.684 71.822 262.162 65.7868L156.951 5.01874C146.43 -1.01645 133.617 -1.01645 123.096 5.01874L17.8843 65.6828C7.36316 71.718 0.904633 82.8518 0.904633 95.0263V216.458C0.904633 228.529 7.36316 239.663 17.8843 245.698L123.096 306.362C133.617 312.397 146.43 312.397 156.951 306.362L262.267 245.594C272.684 239.663 279.142 228.529 279.142 216.458Z" fill="#FF8038"/>
|
|
3
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M140.075 292.21C137.471 292.21 134.867 291.482 132.471 290.233L27.2596 229.465C22.5719 226.76 19.6552 221.765 19.6552 216.354V95.0263C19.6552 89.6154 22.5719 84.6208 27.1554 81.9154L132.471 21.1473C134.763 19.7945 137.367 19.1702 140.075 19.1702C142.784 19.1702 145.284 19.8986 147.68 21.1473L252.995 81.9154C257.683 84.6208 260.6 89.6154 260.6 95.0263V216.458C260.6 221.869 257.683 226.864 252.995 229.569L147.68 290.337C145.284 291.482 142.68 292.21 140.075 292.21Z" fill="#9CFC61"/>
|
|
4
|
+
<mask id="mask0_4_3" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="10" y="133" width="259" height="61">
|
|
5
|
+
<path d="M10.6457 133.301H268.646V193.301H10.6457V133.301Z" fill="white"/>
|
|
6
6
|
</mask>
|
|
7
|
-
<g mask="url(#
|
|
8
|
-
<path fill-rule="evenodd" clip-rule="evenodd" d="
|
|
7
|
+
<g mask="url(#mask0_4_3)">
|
|
8
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M10.6457 34.2317H268.646V292.232H10.6457V34.2317Z" fill="#FF8038"/>
|
|
9
9
|
</g>
|
|
10
|
-
<mask id="
|
|
11
|
-
<path d="
|
|
10
|
+
<mask id="mask1_4_3" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="122" y="244" width="36" height="35">
|
|
11
|
+
<path d="M122 244H157.139V278.037H122V244Z" fill="white"/>
|
|
12
12
|
</mask>
|
|
13
|
-
<g mask="url(#
|
|
14
|
-
<path fill-rule="evenodd" clip-rule="evenodd" d="
|
|
13
|
+
<g mask="url(#mask1_4_3)">
|
|
14
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M144.917 255.167L157.139 256.912L148.335 265.657L150.471 277.948L139.523 272.186L128.621 278.037L130.658 265.73L121.785 257.056L133.993 255.212L139.41 244L144.917 255.167Z" fill="white"/>
|
|
15
15
|
</g>
|
|
16
|
-
<path fill-rule="evenodd" clip-rule="evenodd" d="
|
|
17
|
-
<path d="
|
|
16
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M178.87 65.8803C178.87 64.6713 178.312 63.7413 177.289 63.0903C177.103 62.9973 176.824 62.8113 176.638 62.7183C176.638 59.6494 176.545 56.4875 176.359 53.3256C175.987 46.0718 172.174 42.5378 165.013 42.4448C158.782 42.4448 152.551 42.4448 146.32 42.4448C136.183 42.4448 126.139 42.3518 116.002 42.5378C106.702 42.7238 102.982 46.6297 102.982 55.9295C102.982 58.1614 102.982 60.3934 102.982 62.7183C102.424 62.9043 101.959 63.3693 101.587 63.8343C100.936 64.3923 100.75 65.2293 100.75 66.1592C100.75 70.4371 100.75 74.715 100.75 79.0859C100.75 80.3879 101.215 81.4109 102.331 82.0618C102.61 82.2478 102.796 82.3408 103.075 82.4338C103.075 91.6406 103.075 100.754 103.075 109.961C103.075 111.263 102.889 112.751 103.54 113.867C104.935 116.099 104.656 118.517 104.749 120.935C104.842 123.911 106.795 125.957 109.771 126.05C111.91 126.143 114.049 126.143 116.188 126.05C119.257 125.957 121.21 124.19 121.303 121.121C121.396 119.819 121.582 119.354 123.07 119.354C134.23 119.447 145.483 119.447 156.643 119.354C158.038 119.354 158.41 119.726 158.41 121.121C158.503 124.376 160.456 126.05 163.711 126.05C165.571 126.05 167.431 126.05 169.291 126.05C173.104 126.05 174.964 124.097 175.057 120.284C175.057 118.796 174.592 117.122 175.429 115.727C176.452 113.867 176.731 112.007 176.731 109.961C176.731 101.312 176.731 92.6636 176.731 82.4338C177.382 82.3408 177.94 81.7829 178.312 81.2249C178.777 80.6669 178.963 79.9229 178.963 79.1789C178.87 74.808 178.87 70.3441 178.87 65.8803ZM124.279 49.1407C129.859 49.1407 135.439 49.1407 140.926 49.1407C146.32 49.1407 151.714 49.1407 157.201 49.1407C159.619 49.1407 159.898 49.5127 159.991 52.3026C159.991 55.3715 159.712 55.8365 157.387 55.8365C146.32 55.8365 135.253 55.8365 124.279 55.8365C121.861 55.8365 121.396 55.2785 121.396 52.4886C121.303 49.6987 121.768 49.1407 124.279 49.1407ZM117.304 111.077C114.049 111.077 111.352 108.38 111.352 105.125C111.445 101.963 114.142 99.3594 117.211 99.3594C120.466 99.3594 122.884 101.87 122.884 105.218C122.977 108.473 120.466 111.077 117.304 111.077ZM116.467 90.9896C112.933 90.9896 111.352 89.3157 111.352 85.6888C111.352 79.1789 111.352 72.6691 111.352 66.1592C111.352 62.5323 112.84 61.0444 116.467 61.0444C124.279 61.0444 131.998 61.0444 139.81 61.0444C147.436 61.0444 155.062 61.0444 162.688 61.0444C166.78 61.0444 168.175 62.4393 168.175 66.4382C168.175 72.6691 168.175 78.8999 168.175 85.1308C168.175 88.8507 166.129 90.8966 162.409 90.9896C147.157 90.9896 131.812 90.9896 116.467 90.9896ZM162.409 111.077C159.247 111.077 156.736 108.566 156.643 105.311C156.643 101.963 159.061 99.4524 162.316 99.4524C165.571 99.4524 168.268 102.149 168.268 105.404C168.175 108.38 165.571 111.077 162.409 111.077Z" fill="white"/>
|
|
17
|
+
<path d="M22.6277 153.8H19.5227V151.1H28.7027V153.8H25.5977V170H22.6277V153.8ZM30.1407 151.1H34.5417C36.0717 151.1 37.1877 151.46 37.8897 152.18C38.5917 152.882 38.9427 153.971 38.9427 155.447V156.608C38.9427 158.57 38.2947 159.812 36.9987 160.334V160.388C37.7187 160.604 38.2227 161.045 38.5107 161.711C38.8167 162.377 38.9697 163.268 38.9697 164.384V167.705C38.9697 168.245 38.9877 168.686 39.0237 169.028C39.0597 169.352 39.1497 169.676 39.2937 170H36.2697C36.1617 169.694 36.0897 169.406 36.0537 169.136C36.0177 168.866 35.9997 168.38 35.9997 167.678V164.222C35.9997 163.358 35.8557 162.755 35.5677 162.413C35.2977 162.071 34.8207 161.9 34.1367 161.9H33.1107V170H30.1407V151.1ZM34.1907 159.2C34.7847 159.2 35.2257 159.047 35.5137 158.741C35.8197 158.435 35.9727 157.922 35.9727 157.202V155.744C35.9727 155.06 35.8467 154.565 35.5947 154.259C35.3607 153.953 34.9827 153.8 34.4607 153.8H33.1107V159.2H34.1907ZM43.3253 151.1H47.3483L50.4263 170H47.4563L46.9163 166.247V166.301H43.5413L43.0013 170H40.2473L43.3253 151.1ZM46.5653 163.736L45.2423 154.394H45.1883L43.8923 163.736H46.5653ZM51.8673 151.1H55.5933L58.4823 162.413H58.5363V151.1H61.1823V170H58.1313L54.5673 156.203H54.5133V170H51.8673V151.1ZM67.2507 170.27C65.8107 170.27 64.7217 169.865 63.9837 169.055C63.2457 168.227 62.8767 167.048 62.8767 165.518V164.438H65.6847V165.734C65.6847 166.958 66.1977 167.57 67.2237 167.57C67.7277 167.57 68.1057 167.426 68.3577 167.138C68.6277 166.832 68.7627 166.346 68.7627 165.68C68.7627 164.888 68.5827 164.195 68.2227 163.601C67.8627 162.989 67.1967 162.26 66.2247 161.414C65.0007 160.334 64.1457 159.362 63.6597 158.498C63.1737 157.616 62.9307 156.626 62.9307 155.528C62.9307 154.034 63.3087 152.882 64.0647 152.072C64.8207 151.244 65.9187 150.83 67.3587 150.83C68.7807 150.83 69.8517 151.244 70.5717 152.072C71.3097 152.882 71.6787 154.052 71.6787 155.582V156.365H68.8707V155.393C68.8707 154.745 68.7447 154.277 68.4927 153.989C68.2407 153.683 67.8717 153.53 67.3857 153.53C66.3957 153.53 65.9007 154.133 65.9007 155.339C65.9007 156.023 66.0807 156.662 66.4407 157.256C66.8187 157.85 67.4937 158.57 68.4657 159.416C69.7077 160.496 70.5627 161.477 71.0307 162.359C71.4987 163.241 71.7327 164.276 71.7327 165.464C71.7327 167.012 71.3457 168.2 70.5717 169.028C69.8157 169.856 68.7087 170.27 67.2507 170.27ZM73.4356 151.1H76.4056V170H73.4356V151.1ZM80.9519 153.8H77.8469V151.1H87.0269V153.8H83.9219V170H80.9519V153.8ZM92.7891 151.1H97.3251C98.8011 151.1 99.9081 151.496 100.646 152.288C101.384 153.08 101.753 154.241 101.753 155.771V165.329C101.753 166.859 101.384 168.02 100.646 168.812C99.9081 169.604 98.8011 170 97.3251 170H92.7891V151.1ZM97.2711 167.3C97.7571 167.3 98.1261 167.156 98.3781 166.868C98.6481 166.58 98.7831 166.112 98.7831 165.464V155.636C98.7831 154.988 98.6481 154.52 98.3781 154.232C98.1261 153.944 97.7571 153.8 97.2711 153.8H95.7591V167.3H97.2711ZM103.758 151.1H111.858V153.8H106.728V158.795H110.805V161.495H106.728V167.3H111.858V170H103.758V151.1ZM113.566 151.1H117.94C119.416 151.1 120.523 151.496 121.261 152.288C121.999 153.08 122.368 154.241 122.368 155.771V157.634C122.368 159.164 121.999 160.325 121.261 161.117C120.523 161.909 119.416 162.305 117.94 162.305H116.536V170H113.566V151.1ZM117.94 159.605C118.426 159.605 118.786 159.47 119.02 159.2C119.272 158.93 119.398 158.471 119.398 157.823V155.582C119.398 154.934 119.272 154.475 119.02 154.205C118.786 153.935 118.426 153.8 117.94 153.8H116.536V159.605H117.94ZM125.327 151.1H129.35L132.428 170H129.458L128.918 166.247V166.301H125.543L125.003 170H122.249L125.327 151.1ZM128.567 163.736L127.244 154.394H127.19L125.894 163.736H128.567ZM133.869 151.1H138.27C139.8 151.1 140.916 151.46 141.618 152.18C142.32 152.882 142.671 153.971 142.671 155.447V156.608C142.671 158.57 142.023 159.812 140.727 160.334V160.388C141.447 160.604 141.951 161.045 142.239 161.711C142.545 162.377 142.698 163.268 142.698 164.384V167.705C142.698 168.245 142.716 168.686 142.752 169.028C142.788 169.352 142.878 169.676 143.022 170H139.998C139.89 169.694 139.818 169.406 139.782 169.136C139.746 168.866 139.728 168.38 139.728 167.678V164.222C139.728 163.358 139.584 162.755 139.296 162.413C139.026 162.071 138.549 161.9 137.865 161.9H136.839V170H133.869V151.1ZM137.919 159.2C138.513 159.2 138.954 159.047 139.242 158.741C139.548 158.435 139.701 157.922 139.701 157.202V155.744C139.701 155.06 139.575 154.565 139.323 154.259C139.089 153.953 138.711 153.8 138.189 153.8H136.839V159.2H137.919ZM147.028 153.8H143.923V151.1H153.103V153.8H149.998V170H147.028V153.8ZM158.861 170.27C157.421 170.27 156.323 169.865 155.567 169.055C154.811 168.227 154.433 167.048 154.433 165.518V151.1H157.403V165.734C157.403 166.382 157.529 166.85 157.781 167.138C158.051 167.426 158.429 167.57 158.915 167.57C159.401 167.57 159.77 167.426 160.022 167.138C160.292 166.85 160.427 166.382 160.427 165.734V151.1H163.289V165.518C163.289 167.048 162.911 168.227 162.155 169.055C161.399 169.865 160.301 170.27 158.861 170.27ZM165.404 151.1H169.805C171.335 151.1 172.451 151.46 173.153 152.18C173.855 152.882 174.206 153.971 174.206 155.447V156.608C174.206 158.57 173.558 159.812 172.262 160.334V160.388C172.982 160.604 173.486 161.045 173.774 161.711C174.08 162.377 174.233 163.268 174.233 164.384V167.705C174.233 168.245 174.251 168.686 174.287 169.028C174.323 169.352 174.413 169.676 174.557 170H171.533C171.425 169.694 171.353 169.406 171.317 169.136C171.281 168.866 171.263 168.38 171.263 167.678V164.222C171.263 163.358 171.119 162.755 170.831 162.413C170.561 162.071 170.084 161.9 169.4 161.9H168.374V170H165.404V151.1ZM169.454 159.2C170.048 159.2 170.489 159.047 170.777 158.741C171.083 158.435 171.236 157.922 171.236 157.202V155.744C171.236 155.06 171.11 154.565 170.858 154.259C170.624 153.953 170.246 153.8 169.724 153.8H168.374V159.2H169.454ZM176.294 151.1H184.394V153.8H179.264V158.795H183.341V161.495H179.264V167.3H184.394V170H176.294V151.1ZM190.016 170.27C188.576 170.27 187.487 169.865 186.749 169.055C186.011 168.227 185.642 167.048 185.642 165.518V164.438H188.45V165.734C188.45 166.958 188.963 167.57 189.989 167.57C190.493 167.57 190.871 167.426 191.123 167.138C191.393 166.832 191.528 166.346 191.528 165.68C191.528 164.888 191.348 164.195 190.988 163.601C190.628 162.989 189.962 162.26 188.99 161.414C187.766 160.334 186.911 159.362 186.425 158.498C185.939 157.616 185.696 156.626 185.696 155.528C185.696 154.034 186.074 152.882 186.83 152.072C187.586 151.244 188.684 150.83 190.124 150.83C191.546 150.83 192.617 151.244 193.337 152.072C194.075 152.882 194.444 154.052 194.444 155.582V156.365H191.636V155.393C191.636 154.745 191.51 154.277 191.258 153.989C191.006 153.683 190.637 153.53 190.151 153.53C189.161 153.53 188.666 154.133 188.666 155.339C188.666 156.023 188.846 156.662 189.206 157.256C189.584 157.85 190.259 158.57 191.231 159.416C192.473 160.496 193.328 161.477 193.796 162.359C194.264 163.241 194.498 164.276 194.498 165.464C194.498 167.012 194.111 168.2 193.337 169.028C192.581 169.856 191.474 170.27 190.016 170.27ZM199.823 151.1H202.685L204.008 165.626H204.062L205.466 151.1H208.706L210.11 165.626H210.164L211.487 151.1H214.052L212.135 170H208.436L207.086 157.256H207.032L205.682 170H201.74L199.823 151.1ZM215.555 151.1H218.525V170H215.555V151.1ZM220.749 151.1H225.285C226.761 151.1 227.868 151.496 228.606 152.288C229.344 153.08 229.713 154.241 229.713 155.771V165.329C229.713 166.859 229.344 168.02 228.606 168.812C227.868 169.604 226.761 170 225.285 170H220.749V151.1ZM225.231 167.3C225.717 167.3 226.086 167.156 226.338 166.868C226.608 166.58 226.743 166.112 226.743 165.464V155.636C226.743 154.988 226.608 154.52 226.338 154.232C226.086 153.944 225.717 153.8 225.231 153.8H223.719V167.3H225.231ZM235.93 170.27C234.49 170.27 233.392 169.865 232.636 169.055C231.88 168.227 231.502 167.048 231.502 165.518V155.582C231.502 154.052 231.88 152.882 232.636 152.072C233.392 151.244 234.49 150.83 235.93 150.83C237.37 150.83 238.468 151.244 239.224 152.072C239.98 152.882 240.358 154.052 240.358 155.582V157.202H237.55V155.393C237.55 154.151 237.037 153.53 236.011 153.53C234.985 153.53 234.472 154.151 234.472 155.393V165.734C234.472 166.958 234.985 167.57 236.011 167.57C237.037 167.57 237.55 166.958 237.55 165.734V162.035H236.065V159.335H240.358V165.518C240.358 167.048 239.98 168.227 239.224 169.055C238.468 169.865 237.37 170.27 235.93 170.27ZM242.265 151.1H250.365V153.8H245.235V158.795H249.312V161.495H245.235V167.3H250.365V170H242.265V151.1ZM254.395 153.8H251.29V151.1H260.47V153.8H257.365V170H254.395V153.8Z" fill="white"/>
|
|
18
18
|
</svg>
|
package/lib/file-utils.js
CHANGED
|
@@ -89,6 +89,7 @@ export function copyStaticAssets(exportPath) {
|
|
|
89
89
|
fileURLToPath(import.meta.url),
|
|
90
90
|
'../../public',
|
|
91
91
|
)
|
|
92
|
+
copydir.sync(path.join(staticAssetPath, 'img'), path.join(exportPath, 'img'))
|
|
92
93
|
copydir.sync(path.join(staticAssetPath, 'css'), path.join(exportPath, 'css'))
|
|
93
94
|
copydir.sync(path.join(staticAssetPath, 'js'), path.join(exportPath, 'js'))
|
|
94
95
|
}
|
|
@@ -9,6 +9,7 @@ import { copyStaticAssets, prepDirectory } from './file-utils.js'
|
|
|
9
9
|
import { log, logWarning, logError } from './log-utils.js'
|
|
10
10
|
import {
|
|
11
11
|
generateTransitDeparturesWidgetHtml,
|
|
12
|
+
generateTransitDeparturesWidgetJson,
|
|
12
13
|
setDefaultConfig,
|
|
13
14
|
} from './utils.js'
|
|
14
15
|
|
|
@@ -58,6 +59,7 @@ async function transitDeparturesWidget(initialConfig) {
|
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
await prepDirectory(exportPath)
|
|
62
|
+
await prepDirectory(path.join(exportPath, 'data'))
|
|
61
63
|
|
|
62
64
|
if (config.noHead !== true) {
|
|
63
65
|
copyStaticAssets(exportPath)
|
|
@@ -67,6 +69,17 @@ async function transitDeparturesWidget(initialConfig) {
|
|
|
67
69
|
|
|
68
70
|
config.assetPath = ''
|
|
69
71
|
|
|
72
|
+
// Generate JSON of routes and stops
|
|
73
|
+
const { routes, stops } = generateTransitDeparturesWidgetJson(config)
|
|
74
|
+
await writeFile(
|
|
75
|
+
path.join(exportPath, 'data', 'routes.json'),
|
|
76
|
+
JSON.stringify(routes, null, 2),
|
|
77
|
+
)
|
|
78
|
+
await writeFile(
|
|
79
|
+
path.join(exportPath, 'data', 'stops.json'),
|
|
80
|
+
JSON.stringify(stops, null, 2),
|
|
81
|
+
)
|
|
82
|
+
|
|
70
83
|
const html = await generateTransitDeparturesWidgetHtml(config)
|
|
71
84
|
await writeFile(path.join(exportPath, 'index.html'), html)
|
|
72
85
|
|
package/lib/utils.js
CHANGED
|
@@ -175,15 +175,26 @@ function getStopsForDirection(route, direction, config) {
|
|
|
175
175
|
* Generate HTML for transit departures widget.
|
|
176
176
|
*/
|
|
177
177
|
export function generateTransitDeparturesWidgetHtml(config) {
|
|
178
|
-
const routes = getRoutes()
|
|
179
|
-
const stops = []
|
|
180
|
-
const filteredRoutes = []
|
|
181
178
|
i18n.configure({
|
|
182
179
|
directory: join(dirname(fileURLToPath(import.meta.url)), '..', 'locales'),
|
|
183
180
|
defaultLocale: config.locale,
|
|
184
181
|
updateFiles: false,
|
|
185
182
|
})
|
|
186
183
|
|
|
184
|
+
const templateVars = {
|
|
185
|
+
__: i18n.__,
|
|
186
|
+
config,
|
|
187
|
+
}
|
|
188
|
+
return renderFile('widget', templateVars, config)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/*
|
|
192
|
+
* Generate JSON of routes and stops for transit departures widget.
|
|
193
|
+
*/
|
|
194
|
+
export function generateTransitDeparturesWidgetJson(config) {
|
|
195
|
+
const routes = getRoutes()
|
|
196
|
+
const stops = []
|
|
197
|
+
const filteredRoutes = []
|
|
187
198
|
const calendars = getCalendarsForDateRange(config)
|
|
188
199
|
|
|
189
200
|
for (const route of routes) {
|
|
@@ -243,13 +254,31 @@ export function generateTransitDeparturesWidgetHtml(config) {
|
|
|
243
254
|
// Sort unique list of stops
|
|
244
255
|
const sortedStops = sortBy(uniqBy(stops, 'stop_id'), 'stop_name')
|
|
245
256
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
257
|
+
return {
|
|
258
|
+
routes: removeNulls(sortedRoutes),
|
|
259
|
+
stops: removeNulls(sortedStops),
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/*
|
|
264
|
+
* Remove null values from array or object
|
|
265
|
+
*/
|
|
266
|
+
function removeNulls(data) {
|
|
267
|
+
if (Array.isArray(data)) {
|
|
268
|
+
return data
|
|
269
|
+
.map(removeNulls)
|
|
270
|
+
.filter((item) => item !== null && item !== undefined)
|
|
271
|
+
} else if (typeof data === 'object' && data !== null) {
|
|
272
|
+
return Object.entries(data).reduce((acc, [key, value]) => {
|
|
273
|
+
const cleanedValue = removeNulls(value)
|
|
274
|
+
if (cleanedValue !== null && cleanedValue !== undefined) {
|
|
275
|
+
acc[key] = cleanedValue
|
|
276
|
+
}
|
|
277
|
+
return acc
|
|
278
|
+
}, {})
|
|
279
|
+
} else {
|
|
280
|
+
return data
|
|
251
281
|
}
|
|
252
|
-
return renderFile('widget', templateVars, config)
|
|
253
282
|
}
|
|
254
283
|
|
|
255
284
|
/*
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "transit-departures-widget",
|
|
3
3
|
"description": "Build a realtime transit departures tool from GTFS and GTFS-Realtime.",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.4.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"transit",
|
|
7
7
|
"gtfs",
|
|
@@ -32,25 +32,25 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"copy-dir": "^1.3.0",
|
|
34
34
|
"express": "^4.19.2",
|
|
35
|
-
"gtfs": "^4.
|
|
35
|
+
"gtfs": "^4.12.0",
|
|
36
36
|
"i18n": "^0.15.1",
|
|
37
37
|
"js-beautify": "^1.15.1",
|
|
38
38
|
"lodash-es": "^4.17.21",
|
|
39
39
|
"morgan": "^1.10.0",
|
|
40
40
|
"pretty-error": "^4.0.0",
|
|
41
|
-
"pug": "^3.0.
|
|
41
|
+
"pug": "^3.0.3",
|
|
42
42
|
"sanitize-filename": "^1.6.3",
|
|
43
43
|
"sqlstring-sqlite": "^0.1.1",
|
|
44
44
|
"timer-machine": "^1.1.0",
|
|
45
45
|
"toposort": "^2.0.2",
|
|
46
46
|
"untildify": "^5.0.0",
|
|
47
47
|
"yargs": "^17.7.2",
|
|
48
|
-
"yoctocolors": "^2.
|
|
48
|
+
"yoctocolors": "^2.1.1"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"husky": "^9.0.11",
|
|
52
|
-
"lint-staged": "^15.2.
|
|
53
|
-
"prettier": "^3.2
|
|
52
|
+
"lint-staged": "^15.2.7",
|
|
53
|
+
"prettier": "^3.3.2"
|
|
54
54
|
},
|
|
55
55
|
"engines": {
|
|
56
56
|
"node": ">= 14.15.4"
|
|
@@ -38,7 +38,7 @@ function setupTransitDeparturesWidget(routes, stops, config) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
function formatDirectionId(directionId) {
|
|
41
|
-
if (directionId === null) {
|
|
41
|
+
if (directionId === null || directionId === undefined) {
|
|
42
42
|
return '0'
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -342,13 +342,30 @@ function setupTransitDeparturesWidget(routes, stops, config) {
|
|
|
342
342
|
}
|
|
343
343
|
|
|
344
344
|
function filterDepartures(departures, { selectedStops, direction, route }) {
|
|
345
|
-
// Remove departure information for last stoptime by stop_sequence if it has any
|
|
345
|
+
// Remove departure and arrival information for last stoptime by stop_sequence if it has any
|
|
346
346
|
const cleanedDepartures = departures.map((departure) => {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
347
|
+
if (departure?.trip_update?.stop_time_update?.length > 0) {
|
|
348
|
+
// Find index of largest stop_sequence
|
|
349
|
+
let largestStopSequence = 0
|
|
350
|
+
let largestStopSequenceIndex = 0
|
|
351
|
+
for (
|
|
352
|
+
let index = 0;
|
|
353
|
+
index < departure.trip_update.stop_time_update.length;
|
|
354
|
+
index++
|
|
355
|
+
) {
|
|
356
|
+
if (
|
|
357
|
+
departure.trip_update.stop_time_update[index].stop_sequence >
|
|
358
|
+
largestStopSequence
|
|
359
|
+
) {
|
|
360
|
+
largestStopSequence =
|
|
361
|
+
departure.trip_update.stop_time_update[index].stop_sequence
|
|
362
|
+
largestStopSequenceIndex = index
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
departure.trip_update.stop_time_update.splice(
|
|
366
|
+
largestStopSequenceIndex,
|
|
367
|
+
1,
|
|
368
|
+
)
|
|
352
369
|
}
|
|
353
370
|
|
|
354
371
|
return departure
|
|
@@ -605,7 +622,10 @@ function setupTransitDeparturesWidget(routes, stops, config) {
|
|
|
605
622
|
source(query, populateResults) {
|
|
606
623
|
const filteredResults = stops.filter((stop) => {
|
|
607
624
|
// Don't list child stations
|
|
608
|
-
if (
|
|
625
|
+
if (
|
|
626
|
+
stop.parent_station !== null &&
|
|
627
|
+
stop.parent_station !== undefined
|
|
628
|
+
) {
|
|
609
629
|
return false
|
|
610
630
|
}
|
|
611
631
|
|
package/views/widget/widget.pug
CHANGED
|
@@ -49,13 +49,12 @@
|
|
|
49
49
|
.departure-results-error= __('Unable to fetch departures')
|
|
50
50
|
|
|
51
51
|
script.
|
|
52
|
-
(function() {
|
|
53
|
-
const routes =
|
|
54
|
-
const stops =
|
|
55
|
-
|
|
52
|
+
(async function() {
|
|
53
|
+
const routes = await fetch('data/routes.json').then(res => res.json())
|
|
54
|
+
const stops = await fetch('data/stops.json').then(res => res.json())
|
|
55
|
+
setupTransitDeparturesWidget(routes, stops, {
|
|
56
56
|
gtfsRtTripupdatesUrl: '#{config.agency.gtfs_rt_tripupdates_url}',
|
|
57
57
|
refreshIntervalSeconds: #{config.refreshIntervalSeconds},
|
|
58
58
|
timeFormat: '#{config.timeFormat}'
|
|
59
|
-
}
|
|
60
|
-
setupTransitDeparturesWidget(routes, stops, config);
|
|
59
|
+
})
|
|
61
60
|
})()
|