Separate pages for news to share

Signed-off-by: Alexander Borsuk <me@alex.bio>
This commit is contained in:
Alexander Borsuk 2022-02-07 00:20:09 +01:00 committed by Alexander Borsuk
parent a1c8f520b5
commit 3e3d02b5d2
94 changed files with 416 additions and 142 deletions

View file

@ -15,6 +15,7 @@ external_links_target_blank = true
paths = "safe"
[languages.en.translations]
back = "Back to News"
contact = "Contact Us"
donate = "Donate"
home = "Home"

View file

@ -1,5 +0,0 @@
---
date: "2021-06-20T12:12:15+00:00"
---
Android 5 support, OSM login, bookmarks export, and some other fixes are already in review, as the CarPlay for iOS. Please be patient, or install the latest betas.

View file

@ -1,7 +0,0 @@
---
date: "2021-06-20T12:16:55+00:00"
---
To import bookmarks from MapsMe and other apps which support KML/KMZ on Android, open Bookmarks menu from the bottom toolbar and press Import button.
Automated import from iOS is not technically possible, so here is a small guide

View file

@ -1,4 +0,0 @@
---
date: "2021-06-20T12:16:56+00:00"
---

View file

@ -1,5 +0,0 @@
---
date: "2021-06-24T08:42:03+00:00"
---
A list of maps data mirrors (supported by community enthusiasts) for those in need is available here: <https://cdn.organicmaps.app/>

View file

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 47 KiB

View file

@ -1,5 +1,7 @@
---
date: "2021-05-06T07:20:28+00:00"
title: 'No more trackers according to the latest Exodus Privacy Report!'
date: 2021-05-06T07:20:28+00:00
slug: "no-more-trackers-according-to-the-latest-exodus-privacy-report"
---
No more trackers according to the latest Exodus Privacy Report!

View file

@ -0,0 +1,4 @@
---
date: 2021-05-06
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2021-05-09T08:00:03+00:00"
title: 'A new version 2021-05-08 is availiable for iOS and Android.'
date: 2021-05-09T08:00:03+00:00
slug: "a-new-version-is-availiable-for-ios-and-android"
---
A new version 2021-05-08 is availiable for iOS and Android.

View file

@ -0,0 +1,4 @@
---
date: 2021-05-09
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2021-05-24T07:03:54+00:00"
title: 'A new beta version 2021-05-21 is out.'
date: 2021-05-24T07:03:54+00:00
slug: "a-new-beta-version-is-out"
---
A new beta version 2021-05-21 is out.

View file

@ -0,0 +1,4 @@
---
date: 2021-05-24
sort_by: date
---

View file

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View file

@ -0,0 +1,9 @@
---
title: 'Organic Maps app is now available on F-Droid!'
date: 2021-05-25T21:40:15+00:00
slug: "organic-maps-app-is-now-available-on-f-droid"
---
Organic Maps app is now available on F-Droid!
<https://f-droid.org/en/packages/app.organicmaps/>

View file

@ -0,0 +1,4 @@
---
date: 2021-05-25
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2021-06-06T16:56:44+00:00"
title: 'New GitHub page 🗺'
date: 2021-06-06T16:56:44+00:00
slug: "new-github-page"
---
New GitHub page 🗺

View file

@ -0,0 +1,4 @@
---
date: 2021-06-06
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2021-06-17T08:17:18+00:00"
title: '🍃 Organic Maps is live!'
date: 2021-06-17T08:17:18+00:00
slug: "organic-maps-is-live"
---
🍃 Organic Maps is live!

View file

@ -0,0 +1,4 @@
---
date: 2021-06-17
sort_by: date
---

View file

@ -0,0 +1,7 @@
---
title: 'Android 5 support, OSM login, bookmarks export, and some other fixes are already in review, as the CarPlay for iOS'
date: 2021-06-20T12:12:15+00:00
slug: "android-5-support-osm-login-bookmarks-export-and-some-other-fixes-are-already-in-review-as-the-carplay-for-ios"
---
Android 5 support, OSM login, bookmarks export, and some other fixes are already in review, as the CarPlay for iOS. Please be patient, or install the latest betas.

View file

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

View file

@ -0,0 +1,9 @@
---
title: 'To import bookmarks from MapsMe and other apps which support KML/KMZ on Android, open Bookmarks menu from the bottom toolbar and press Import button.'
date: 2021-06-20T12:16:55+00:00
slug: "to-import-bookmarks-from-mapsme-and-other-apps-which-support-kml-kmz-on-android-open-bookmarks-menu-from-the-bottom-toolbar-and-press-import-button"
---
To import bookmarks from MapsMe and other apps which support KML/KMZ on Android, open Bookmarks menu from the bottom toolbar and press Import button.
Automated import from iOS is not technically possible, so here is a small guide

View file

@ -1,5 +1,7 @@
---
date: "2021-06-20T21:59:30+00:00"
title: 'There are already many requests from users to add public transport support'
date: 2021-06-20T21:59:30+00:00
slug: "there-are-already-many-requests-from-users-to-add-public-transport-support"
---
There are already many requests from users to add public transport support. It would be great to start using that existing OpenStreetMap data and add/update transport schedules directly from the app. For anyone interested to volunteer, there is also a good starting point here: <https://github.com/organicmaps/organicmaps/blob/master/docs/EXPERIMENTAL%5FPUBLIC%5FTRANSPORT%5FSUPPORT.md>

View file

@ -0,0 +1,4 @@
---
date: 2021-06-20
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2021-06-23T20:15:35+00:00"
title: '🚗 iOS update with a (finally!) working CarPlay is live'
date: 2021-06-23T20:15:35+00:00
slug: "ios-update-with-a-finally-working-carplay-is-live"
---
🚗 iOS update with a (finally!) working CarPlay is live. Happy driving!

View file

@ -0,0 +1,4 @@
---
date: 2021-06-23
sort_by: date
---

View file

@ -0,0 +1,7 @@
---
title: 'A list of maps data mirrors (supported by community enthusiasts) for those in need is available here'
date: 2021-06-24T08:42:03+00:00
slug: "a-list-of-maps-data-mirrors-supported-by-community-enthusiasts-for-those-in-need-is-available-here"
---
A list of maps data mirrors (supported by community enthusiasts) for those in need is available here: <https://cdn.organicmaps.app/>

View file

@ -0,0 +1,4 @@
---
date: 2021-06-24
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2021-06-28T13:14:02+00:00"
title: 'A new 2021-06-24 update is available on Google Play 📦'
date: 2021-06-28T13:14:02+00:00
slug: "a-new-update-is-available-on-google-play"
---
A new 2021-06-24 update is available on Google Play 📦

View file

@ -0,0 +1,4 @@
---
date: 2021-06-28
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2021-07-10T15:23:44+00:00"
title: 'Updated OM 🧘 version 2021.07.08 is here!'
date: 2021-07-10T15:23:44+00:00
slug: "updated-om-version-is-here"
---
Updated OM 🧘 version 2021.07.08 is here!

View file

@ -0,0 +1,4 @@
---
date: 2021-07-10
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2021-08-07T06:40:46+00:00"
title: 'Meet a new app update with'
date: 2021-08-07T06:40:46+00:00
slug: "meet-a-new-app-update-with"
---
Meet a new app update with:

View file

@ -0,0 +1,4 @@
---
date: 2021-08-07
sort_by: date
---

View file

@ -0,0 +1,8 @@
---
title: 'News for anyone who wants to support the development of free, open-source, offline, privacy-focused maps for travelers, hikers, motorists, and cyclists'
date: 2021-08-13T08:16:47+00:00
slug: "news-for-anyone-who-wants-to-support-the-development-of-free-open-source-offline-privacy-focused-maps-for-travelers-hikers-motorists-and-cyclists"
---
News for anyone who wants to support the development of free, open-source, offline, privacy-focused maps for travelers, hikers, motorists, and cyclists. We're accepting 💰donations for servers and new features for your favorite app.
Read more here: <https://organicmaps.app/donate/>

View file

@ -0,0 +1,4 @@
---
date: 2021-08-13
sort_by: date
---

View file

@ -0,0 +1,7 @@
---
title: 'We have a temporary issue with Google Play app availability'
date: 2021-08-15T15:14:17+00:00
slug: "we-have-a-temporary-issue-with-google-play-app-availability"
---
We have a temporary issue with Google Play app availability. Hopefully it will be fixed soon 🤞

View file

@ -0,0 +1,4 @@
---
date: 2021-08-15
sort_by: date
---

View file

@ -0,0 +1,9 @@
---
title: 'Organic Maps is back on Google Play after a temporary problem 🎉'
date: 2021-08-16T17:44:40+00:00
slug: "organic-maps-is-back-on-google-play-after-a-temporary-problem"
---
Organic Maps is back on Google Play after a temporary problem 🎉
<https://play.google.com/store/apps/details?id=app.organicmaps>

View file

@ -0,0 +1,4 @@
---
date: 2021-08-16
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2021-08-21T07:46:14+00:00"
title: 'A minor update is available in Google Play'
date: 2021-08-21T07:46:14+00:00
slug: "a-minor-update-is-available-in-google-play"
---
A minor update is available in Google Play <https://omaps.app/gp>

View file

@ -0,0 +1,4 @@
---
date: 2021-08-21
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2021-08-23T09:24:31+00:00"
title: 'A new experimental Android beta version with improved map downloader is available for testing'
date: 2021-08-23T09:24:31+00:00
slug: "a-new-experimental-android-beta-version-with-improved-map-downloader-is-available-for-testing"
---
A new experimental Android beta version with improved map downloader is available for testing:

View file

@ -0,0 +1,4 @@
---
date: 2021-08-23
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2021-08-27T18:34:36+00:00"
title: 'Some highlights about Organic Maps in the French article'
date: 2021-08-27T18:34:36+00:00
slug: "some-highlights-about-organic-maps-in-the-french-article"
---
Some highlights about Organic Maps in the French article: <https://start.lesechos.fr/au-quotidien/voyage-expatriation/organic-maps-lappli-de-navigation-gratuite-qui-respecte-votre-vie-privee-1340970>

View file

@ -0,0 +1,4 @@
---
date: 2021-08-27
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2021-08-30T21:38:20+00:00"
title: 'With the help of our community ❤️, in the 21.08.26 update we'
date: 2021-08-30T21:38:20+00:00
slug: "with-the-help-of-our-community-in-the-update-we"
---
With the help of our community ❤️, in the 21.08.26 update we:

View file

@ -0,0 +1,4 @@
---
date: 2021-08-30
sort_by: date
---

View file

@ -0,0 +1,8 @@
---
title: ' The latest 21.09.01 update is available in Google Play, App Store and AppGallery with updated OSM maps 🗺️ data snapshot, made on 25th of August.'
date: 2021-09-05T20:30:34+00:00
slug: "the-latest-update-is-available-in-google-play-app-store-and-appgallery-with-updated-osm-maps-data-snapshot-made-on-25th-of-august"
---
The latest 21.09.01 update is available in Google Play, App Store and AppGallery with updated OSM maps 🗺️ data snapshot, made on 25th of August.
FDroid version is not available yet, because there are some build issues. But with the help of the community they should be resolved soon 🤞

View file

@ -0,0 +1,4 @@
---
date: 2021-09-05
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2021-09-15T20:34:14+00:00"
title: '21.09.14 app update is available in Google Play'
date: 2021-09-15T20:34:14+00:00
slug: "app-update-is-available-in-google-play"
---
21.09.14 app update is available in Google Play. We:

View file

@ -0,0 +1,4 @@
---
date: 2021-09-15
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2021-09-26T10:04:44+00:00"
title: 'Here is the list of OpenStreetMap metro/subways validation results'
date: 2021-09-26T10:04:44+00:00
slug: "here-is-the-list-of-openstreetmap-metro-subways-validation-results"
---
Here is the list of OpenStreetMap metro/subways validation results:

View file

@ -0,0 +1,4 @@
---
date: 2021-09-26
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2021-10-09T18:07:49+00:00"
title: 'Sorry, the latest 21.10.07 release for Android has a bug'
date: 2021-10-09T18:07:49+00:00
slug: "sorry-the-latest-release-for-android-has-a-bug"
---
Sorry, the latest 21.10.07 release for Android has a bug: if you clicked before on coordinates in the place info (to switch coordinates format), then you'll have a crash on startup. Only reinstall can help (but you'll loose your bookmarks!). If you have root access, then close the app and delete /data/data/[app.organicmaps.app/files/settings.ini](http://app.organicmaps.app/files/settings.ini)

View file

@ -0,0 +1,4 @@
---
date: 2021-10-09
sort_by: date
---

View file

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View file

@ -1,5 +1,7 @@
---
date: "2021-10-14T06:14:09+00:00"
title: 'A new app update is available!'
date: 2021-10-14T06:14:09+00:00
slug: "a-new-app-update-is-available"
---
A new app update is available!

View file

@ -0,0 +1,4 @@
---
date: 2021-10-14
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2021-10-21T09:36:45+00:00"
title: 'In 21.10.15 Google Play update we'
date: 2021-10-21T09:36:45+00:00
slug: "in-google-play-update-we"
---
In 21.10.15 Google Play update we:

View file

@ -0,0 +1,4 @@
---
date: 2021-10-21
sort_by: date
---

View file

@ -0,0 +1,9 @@
---
title: 'Please help with translating Organic Maps into $your_language 🗺️'
date: 2021-11-01T09:22:01+00:00
slug: "please-help-with-translating-organic-maps-into-your-language"
---
Please help with translating Organic Maps into `$your_language` 🗺️
<https://github.com/organicmaps/organicmaps/discussions/1489>

View file

@ -0,0 +1,4 @@
---
date: 2021-11-01
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2021-11-09T22:05:28+00:00"
title: 'Meet November 4 Organic Maps update!'
date: 2021-11-09T22:05:28+00:00
slug: "meet-november-4-organic-maps-update"
---
Meet November 4 Organic Maps update!

View file

@ -0,0 +1,4 @@
---
date: 2021-11-09
sort_by: date
---

View file

Before

Width:  |  Height:  |  Size: 119 KiB

After

Width:  |  Height:  |  Size: 119 KiB

View file

@ -0,0 +1,7 @@
---
title: 'Tell your stories to us and other users'
date: 2021-11-21T19:36:45+00:00
slug: "tell-your-stories-to-us-and-other-users"
---
Tell your stories to us and other users. They ignite and inspire us!

View file

@ -0,0 +1,7 @@
---
title: 'Here is the link to hourly updated OSM data validator related to Public Transport in Organic Maps (subways and light rails)'
date: 2021-11-21T21:33:43+00:00
slug: "here-is-the-link-to-hourly-updated-osm-data-validator-related-to-public-transport-in-organic-maps-subways-and-light-rails"
---
Here is the link to hourly updated OSM data validator related to Public Transport in Organic Maps (subways and light rails). Please, help us to fix red cities in OpenStreetMap and include their subways into the next maps update: <https://cdn.organicmaps.app/subway/>

View file

@ -0,0 +1,4 @@
---
date: 2021-11-21
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2021-12-03T22:18:34+00:00"
title: 'Meet Organic Maps app update 21.12.01'
date: 2021-12-03T22:18:34+00:00
slug: "meet-organic-maps-app-update"
---
Meet Organic Maps app update 21.12.01

View file

@ -0,0 +1,4 @@
---
date: 2021-12-03
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2022-01-14T14:44:07+00:00"
title: 'Meet new January Organic Maps app update, with many improvements from our beloved contributors 🙏!'
date: 2022-01-14T14:44:07+00:00
slug: "meet-new-january-organic-maps-app-update-with-many-improvements-from-our-beloved-contributors"
---
Meet new January Organic Maps app update, with many improvements from our beloved contributors 🙏!

View file

@ -0,0 +1,4 @@
---
date: 2022-01-14
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2022-01-15T13:08:26+00:00"
title: 'There is a regression with KML import on Android'
date: 2022-01-15T13:08:26+00:00
slug: "there-is-a-regression-with-kml-import-on-android"
---
There is a regression with KML import on Android. No worries, the fix is already in review.

View file

@ -0,0 +1,4 @@
---
date: 2022-01-15
sort_by: date
---

View file

@ -0,0 +1,7 @@
---
title: 'Finally, FDroid update is available too'
date: 2022-01-18T11:47:38+00:00
slug: "finally-fdroid-update-is-available-too"
---
Finally, FDroid update is available too: <https://f-droid.org/en/packages/app.organicmaps/>

View file

@ -0,0 +1,4 @@
---
date: 2022-01-18
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2022-01-23T22:52:04+00:00"
title: 'The latest data update also includes an updated subway/metro map'
date: 2022-01-23T22:52:04+00:00
slug: "the-latest-data-update-also-includes-an-updated-subway-metro-map"
---
The latest data update also includes an updated subway/metro map. Please check issues in your cities and fix them in OpenStreetMap for the next data update: <https://cdn.organicmaps.app/subway/>

View file

@ -0,0 +1,4 @@
---
date: 2022-01-23
sort_by: date
---

View file

@ -1,5 +1,7 @@
---
date: "2022-02-02T11:26:11+00:00"
title: 'We''ve created a Telegram group for Turkish users, moderated by @MetehanOzyurek'
date: 2022-02-02T11:26:11+00:00
slug: "we-ve-created-a-telegram-group-for-turkish-users-moderated-by-metehanozyurek"
---
We've created a Telegram group for Turkish users, moderated by [@MetehanOzyurek](https://t.me/MetehanOzyurek)

View file

@ -0,0 +1,4 @@
---
date: 2022-02-02
sort_by: date
---

View file

@ -1,6 +0,0 @@
---
date: "2021-08-13T08:16:47+00:00"
---
News for anyone who wants to support the development of free, open-source, offline, privacy-focused maps for travelers, hikers, motorists, and cyclists. We're accepting 💰donations for servers and new features for your favorite app.
Read more here: <https://organicmaps.app/donate/>

View file

@ -1,5 +0,0 @@
---
date: "2021-08-15T15:14:17+00:00"
---
We have a temporary issue with Google Play app availability. Hopefully it will be fixed soon 🤞

View file

@ -1,7 +0,0 @@
---
date: "2021-08-16T17:44:40+00:00"
---
Organic Maps is back on Google Play after a temporary problem 🎉
<https://play.google.com/store/apps/details?id=app.organicmaps>

View file

@ -1,6 +0,0 @@
---
date: "2021-09-05T20:30:34+00:00"
---
The latest 21.09.01 update is available in Google Play, App Store and AppGallery with updated OSM maps 🗺️ data snapshot, made on 25th of August.
FDroid version is not available yet, because there are some build issues. But with the help of the community they should be resolved soon 🤞

View file

@ -1,7 +0,0 @@
---
date: "2021-11-01T09:22:01+00:00"
---
Please help with translating Organic Maps into `$your_language` 🗺️
<https://github.com/organicmaps/organicmaps/discussions/1489>

View file

@ -1,5 +0,0 @@
---
date: "2021-11-21T19:36:45+00:00"
---
Tell your stories to us and other users. They ignite and inspire us!

View file

@ -1,5 +0,0 @@
---
date: "2021-11-21T21:33:43+00:00"
---
Here is the link to hourly updated OSM data validator related to Public Transport in Organic Maps (subways and light rails). Please, help us to fix red cities in OpenStreetMap and include their subways into the next maps update: <https://cdn.organicmaps.app/subway/>

View file

@ -1,5 +0,0 @@
---
date: "2022-01-18T11:47:38+00:00"
---
Finally, FDroid update is available too: <https://f-droid.org/en/packages/app.organicmaps/>

View file

@ -1,7 +0,0 @@
---
date: "2021-05-25T21:40:15+00:00"
---
Organic Maps app is now available on F-Droid!
<https://f-droid.org/en/packages/app.organicmaps/>

View file

@ -2,6 +2,7 @@
title: "Organic Maps: latest news and updates from our team"
description: Stay in touch with the latest app releases, news and updates from our team!
template: news.html
page_template: news_post.html
sort_by: date
extra:
menu_title: News

View file

@ -17,6 +17,11 @@
{%- set preview_image = 'images/screenshots/prague.jpg' -%}
{%- if resource.extra.preview_image -%}
{%- set preview_image = resource.extra.preview_image -%}
{%- elif resource.assets %}
{%- set basename = resource.assets[0] | split(pat='/') | last %}
{%- if basename is ending_with('.jpg') %}
{%- set preview_image = resource.path ~ basename -%}
{%- endif %}
{%- endif %}
<meta property="og:image" content="{{ get_url(path=preview_image) }}">
<meta property="og:url" content="{{ current_url }}">

19
templates/news_post.html Normal file
View file

@ -0,0 +1,19 @@
{% extends 'base.html' %}
{% block content %}
<h1>{{ resource.date | date(format='%B %e, %Y') }}</h1>
<div class="news_content">
{{ resource.content | safe }}
</div>
{% for photo in resource.assets %}
<img class="news_image" src="{{ resource.path }}/{{ photo | split(pat='/') | last }}" />
{% endfor %}
<div>
<a href="/news">{{ trans(key='back') }}</a>
</div>
{% endblock content %}

View file

@ -1,4 +1,10 @@
// This script fetches Telegram channel preview and extracts content from it for our site.
// How content is stored an rendered:
// On disk:
// content/news/2022-01-30/7/index.md (Telegram ID is used)
// On site:
// /news/2022-01-30/title-text-slug
'use strict';
const channelPreviewUrl = 'https://t.me/s/OrganicMapsApp';
const newsPath = `${__dirname}/content/news/`;
@ -9,6 +15,8 @@ const fs = require('fs');
const NodeHtmlMarkdown = require('node-html-markdown').NodeHtmlMarkdown;
const nhm = new NodeHtmlMarkdown();
const photoUrlRE = /url\(\'(.*?)\'/;
const emojiRE = /_\*\*(\u00a9|\u00ae|[\u2000-\u3300]\ufe0f?|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]\ufe0f?|\ud83e[\ud000-\udfff]|\uD83C[\uDDE6-\uDDFF]\uD83C[\uDDE6-\uDDFF])\*\*_/gi;
function downloadAsync(url, path) {
return new Promise((resolve, reject) => {
@ -27,36 +35,70 @@ function downloadAsync(url, path) {
}).catch(err => console.error('Download failed: ' + err));
}
const emojiRE = /_\*\*(\u00a9|\u00ae|[\u2000-\u3300]\ufe0f?|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]\ufe0f?|\ud83e[\ud000-\udfff]|\uD83C[\uDDE6-\uDDFF]\uD83C[\uDDE6-\uDDFF])\*\*_/gi;
function toMarkdown(node, date) {
let frontmatter = `---\ndate: "${date}"\n---\n\n`;
// Photo-only posts do not have text, but should have an index.md file.
if (node) {
let content = nhm.translate(node.innerHTML);
// We use other dots for lists.
content = content.replaceAll('• ', '* ');
// Telegram makes emoji bold italic.
content = content.replaceAll(emojiRE, '$1');
return frontmatter + content;
// Creates a title for news piece from text.
function getTitle(text) {
// Strip urls and text after them.
const breakers = ['http', '. ', ':', '\n'];
for (let b = 0; b < breakers.length; ++b) {
const i = text.indexOf(breakers[b]);
if (i > 0) text = text.substring(0, i);
}
return frontmatter;
return text.trim();
}
// Download Telegram channel preview html.
const request = https.get(channelPreviewUrl, response => {
if (response.statusCode != 200) throw new Error('statusCode=' + response.statusCode);
let chunks = [];
response.on('data', fragments => chunks.push(fragments));
response.on('end', _ => {
const body = Buffer.concat(chunks);
parseHtml(body.toString());
});
response.on('error', err => console.log(err));
});
request.on('error', err => console.log(err));
request.end();
const dateRE = /-?(\d\d)?\d\d-\d\d-\d\d-?/g;
const slugRE = /(.\ufe0f)?[^\p{L}\p{N}]+/gu;
const kReplacer = '-';
// Removes incompatible symbols from the text. May return an empty string.
function slugify(text) {
text = text.toLowerCase().replace(slugRE, kReplacer);
// Remove version numbers (dates) from slugs.
text = text.replace(dateRE, kReplacer);
if (text.length && text[0] == kReplacer) text = text.substr(1);
if (text.length && text[text.length - 1] == kReplacer) text = text.substr(0, text.length - 1);
return text;
}
function toMarkdown(node, date) {
const time = date.substring(11, 16);
// News web page title.
const title = node ? getTitle(node.structuredText) : time;
let slug = slugify(title);
if (!slug) slug = time.replace(':', '-');
const frontmatter = `---\ntitle: '${title.replaceAll("'", "''")}'\ndate: ${date}\nslug: "${slug}"\n---`;
// Photo-only posts do not have text, but should have an index.md file.
if (!node) return frontmatter;
let content = nhm.translate(node.innerHTML);
// We use other dots for lists.
content = content.replaceAll('• ', '* ');
// Telegram makes emoji bold italic.
content = content.replaceAll(emojiRE, '$1');
return frontmatter + content;
}
if (process.argv.length > 2) {
// Load file from the command line.
console.log('Loading file ' + process.argv[2]);
const html = fs.readFileSync(process.argv[2]);
parseHtml(html);
} else {
// Download Telegram channel preview html.
console.log('Downloading ' + channelPreviewUrl);
const request = https.get(channelPreviewUrl, response => {
if (response.statusCode != 200) throw new Error('statusCode=' + response.statusCode);
let chunks = [];
response.on('data', fragments => chunks.push(fragments));
response.on('end', _ => {
const body = Buffer.concat(chunks);
parseHtml(body.toString());
});
response.on('error', err => console.log(err));
});
request.on('error', err => console.log(err));
request.end();
}
function parseHtml(html) {
const root = parse(html);
@ -65,15 +107,19 @@ function parseHtml(html) {
const messages = root.querySelectorAll('.tgme_widget_message:not(.service_message)');
console.log('Parsing ' + messages.length + ' Telegram posts.');
const downloads = [];
let prevDir;
messages.forEach(m => {
let photos = m.querySelectorAll('.tgme_widget_message_photo_wrap');
let text = m.querySelector('.tgme_widget_message_text');
let date = m.querySelector('time');
date = date.getAttribute('datetime');
let date = m.querySelector('time').getAttribute('datetime');
const id = m.getAttribute('data-post').split('/').pop();
const dir = newsPath + id;
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
const yyyyMMdd = date.substring(0, 10);
const dir = `${newsPath}${yyyyMMdd}/${id}`;;
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(dir + '/../_index.md', `---\ndate: ${yyyyMMdd}\nsort_by: date\n---`);
}
// Each message may have 0 or more photos.
for (let i = 1; i <= photos.length; ++i) {
@ -81,6 +127,13 @@ function parseHtml(html) {
photo = photo.match(photoUrlRE)[1];
const ext = photo.split('.').pop();
const fileName = `${i}.${ext}`;
// Handle two special cases in old news where image was published as a
// separate message after the text. Merge them.
if (id == '15' || id == '39') {
downloads.push(downloadAsync(photo, `${prevDir}/${fileName}`));
fs.rmSync(dir, { recursive: true, force: true });
return;
}
downloads.push(downloadAsync(photo, `${dir}/${fileName}`));
}
@ -88,18 +141,7 @@ function parseHtml(html) {
fs.writeFile(`${dir}/index.md`, markdown, err => {
if (err) console.error(err);
});
});
// Wait until all downloads are finished.
Promise.allSettled(downloads).then(_ => {
// Fix some old posts.
if (fs.existsSync(newsPath + '15')) {
fs.renameSync(newsPath + '15/1.jpg', newsPath + '14/1.jpg');
fs.rmSync(newsPath + '15', { recursive: true, force: true });
}
if (fs.existsSync(newsPath + '39')) {
fs.renameSync(newsPath + '39/1.jpg', newsPath + '38/1.jpg');
fs.rmSync(newsPath + '39', { recursive: true, force: true });
}
prevDir = dir;
});
}