Added news and script to generate them

Signed-off-by: Alexander Borsuk <me@alex.bio>
This commit is contained in:
Alexander Borsuk 2022-02-03 01:11:46 +01:00 committed by Alexander Borsuk
parent e8a7ba3c79
commit 2d4843c734
50 changed files with 626 additions and 5 deletions

View file

@ -18,4 +18,5 @@ paths = "safe"
contact = "Contact Us"
donate = "Donate"
home = "Home"
news = "News"
support-us = "Support Us"

28
content/news/11/index.md Normal file
View file

@ -0,0 +1,28 @@
---
date: "2021-06-06T16:56:44+00:00"
---
New GitHub page 🗺
<https://github.com/organicmaps/organicmaps#readme>
Organic Maps is pure and organic, **made with love**:
☘ Respects your privacy
🌱 Saves your battery
🍃 No unexpected mobile data charges
Organic Map is **free from trackers and other bad stuff**:
✅ No ads
✅ No tracking
✅ No data collection
✅ No phoning home
✅ No annoying registration
✅ No mandatory tutorials
✅ No noisy email spam
✅ No push notifications
✅ No crapware
✅ No pesticides 😇
👉 Reject surveillance - spread the word about Organic Maps!

45
content/news/12/index.md Normal file
View file

@ -0,0 +1,45 @@
---
date: "2021-06-17T08:17:18+00:00"
---
🍃 Organic Maps is live!
iOS:
* Apple AppStore: <https://apps.apple.com/app/organic-maps/id1567437057>
* Beta: <https://testflight.apple.com/join/lrKCl08I>
Android:
* Google Play: <https://play.google.com/store/apps/details?id=app.organicmaps>
* Huawei AppGallery: <https://appgallery.huawei.com/#/app/C104325611>
* F-Droid: <https://f-droid.org/en/packages/app.organicmaps/>
* Beta: <https://appdistribution.firebase.dev/i/3c5fcf9cd72f775f>
GitHub: <https://github.com/organicmaps/organicmaps>
Please give us ⭐ ⭐ ⭐ ⭐ ⭐ on AppStore and Google Play to help this project survive! 🔥
——
Organic Maps is an open-source Android & iOS offline maps app
for travelers, tourists, hikers, and cyclists based on top of crowd-sourced
OpenStreetMap data and curated with love by **MAPSME** founders.
Organic Maps is pure and organic, and **free from trackers and other bad stuff**:
✅ No ads
✅ No tracking
✅ No data collection
✅ No phoning home
✅ No annoying registration
✅ No mandatory tutorials
✅ No noisy email spam
✅ No push notifications
✅ No crapware
✅ No pesticides 😇
<https://t.me/OrganicMaps>
<https://t.me/OrganicMapsRu> (для русскоговорящих)
<https://organicmaps.app/>
<https://github.com/organicmaps/organicmaps>

5
content/news/13/index.md Normal file
View file

@ -0,0 +1,5 @@
---
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.

7
content/news/14/index.md Normal file
View file

@ -0,0 +1,7 @@
---
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

BIN
content/news/15/1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

4
content/news/15/index.md Normal file
View file

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

5
content/news/16/index.md Normal file
View file

@ -0,0 +1,5 @@
---
date: "2021-06-20T21:59:30+00:00"
---
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>

7
content/news/17/index.md Normal file
View file

@ -0,0 +1,7 @@
---
date: "2021-06-23T20:15:35+00:00"
---
🚗 iOS update with a (finally!) working CarPlay is live. Happy driving!
Please don't forget, as there are 0 (zero, none) analytics and statistics libraries in Organic Maps, we rely entirely on your detailed feedback about issues you encounter.

5
content/news/18/index.md Normal file
View file

@ -0,0 +1,5 @@
---
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/>

12
content/news/19/index.md Normal file
View file

@ -0,0 +1,12 @@
---
date: "2021-06-28T13:14:02+00:00"
---
A new 2021-06-24 update is available on Google Play 📦
In this update we:
* Improved maps downloading speed for certain regions
* Fixed uploading of map edits to OpenStreetMap
* Fixed bookmark sharing from Bookmarks (Categories) screen
🍃 🗺

27
content/news/20/index.md Normal file
View file

@ -0,0 +1,27 @@
---
date: "2021-07-10T15:23:44+00:00"
---
Updated OM 🧘 version 2021.07.08 is here!
Both platforms:
* Finally, meet the updated OSM map data!
* Fixed failing OSM login due to OSM backend changes
* Resized car repair, charging station, museum icons
* Updated hostel, kindergarten, clothes, dentist icons with a white filling
* Reduced timeouts for map downloads
* Fixed crash in the search on regions boundaries
* Fixed routing crash when point doesn't belong to any map file (in a gap between)
* Fixed texts in the FAQ
Android:
* Removed annoying top panel when selecting a place on the map
* Fixed issue when new bookmark set is not assigned to the bookmark after creation
* Enabled DownloadManager notifications
* Replaced icons for adding and removing bookmarks
* Fixed "Mobile Internet" settings
iOS:
* Disabled backup for map files
* Removed non-working traffic button in Navigation mode
* Added gradient to the app icon

29
content/news/21/index.md Normal file
View file

@ -0,0 +1,29 @@
---
date: "2021-08-07T06:40:46+00:00"
---
Meet a new app update with:
* 🗺️ Updated OpenStreetMap data
* Added 🇧🇬Bulgarian and 🇧🇷Brazil translations (thanks to our contributors!)
* 🍖Picnic tables are on the map!
* Wrong regions are not offered anymore for cross-region routing
* Improved ETA for remote tracks and roads
* Fixed FAQ
🍏 iOS:
* You can now edit/move/delete tracks and bookmarks
* CarPlay map is properly aligned
* Failed downloads are now resumed
* Aligned bottom bar buttons
🤖 Android:
* Fixed layout bugs, including RTL languages
* Fixed some non-working search queries
* Fixed wrong encoding in bookmark description
* Fixed import of KML/KMZ files
* Silence media volume while announcing navigation directions
* Display and edit multiple phone numbers
* Reduced apk size
As always, we're counting on your feedback about bugs and issues.
Have a happy weekend!

6
content/news/22/index.md Normal file
View file

@ -0,0 +1,6 @@
---
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/>

5
content/news/23/index.md Normal file
View file

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

7
content/news/24/index.md Normal file
View file

@ -0,0 +1,7 @@
---
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>

12
content/news/25/index.md Normal file
View file

@ -0,0 +1,12 @@
---
date: "2021-08-21T07:46:14+00:00"
---
A minor update is available in Google Play <https://omaps.app/gp>
* Fixed download progress stuck at 0% and made it fractional
* Fixed metro/subway entry icons in some cities
* Added "Report a bug" button in the main menu
* Fixed invisible button in the navigation panel on Android 6+
Please let us know if you still have any issues with maps downloading, or any other issues. We will fix them ASAP!

9
content/news/26/index.md Normal file
View file

@ -0,0 +1,9 @@
---
date: "2021-08-23T09:24:31+00:00"
---
A new experimental Android beta version with improved map downloader is available for testing:
<https://appdistribution.firebase.dev/i/9ec3bca5e2b47373>
This version should fix 0% problem once and for all! Please let us know if you still have any issues with maps downloading, or any other issues. We will fix them ASAP!

5
content/news/27/index.md Normal file
View file

@ -0,0 +1,5 @@
---
date: "2021-08-27T18:34:36+00:00"
---
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>

16
content/news/28/index.md Normal file
View file

@ -0,0 +1,16 @@
---
date: "2021-08-30T21:38:20+00:00"
---
With the help of our community ❤️, in the 21.08.26 update we:
* Increased maximum number of intermediate stops from 3 to... try to guess 🙂
* Fixed rare crash when downloading maps
* Made farmlands more visible on the map
* Updated 🇧🇷 Brazil and 🇵🇹 Portuguese translations
On Android, in addition:
* Finally, maps download should work for everyone! You don't need to enable Internet access for Download Manager anymore!
* Bookmark button ⭐ shows "Save" and "Delete" instead of just "Bookmark"
Get it here: <https://omaps.app/get>

6
content/news/29/index.md Normal file
View file

@ -0,0 +1,6 @@
---
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 🤞

8
content/news/30/index.md Normal file
View file

@ -0,0 +1,8 @@
---
date: "2021-09-15T20:34:14+00:00"
---
21.09.14 app update is available in Google Play. We:
* Fixed missing buttons on the toolbar after the search on Android 11, very annoying bug 🐞!
* Updated some translations, thanks to our contributors ❤️
* Fixed incorrectly toggled WiFi when editing a phone number

21
content/news/31/index.md Normal file
View file

@ -0,0 +1,21 @@
---
date: "2021-09-26T10:04:44+00:00"
---
Here is the list of OpenStreetMap metro/subways validation results:
<https://cdn.organicmaps.app/subway/> (hourly)
or
<https://maps.mail.ru/osm/tools/subways/latest/>
or
<https://alexey-zakharenkov.github.io/subways/rapid/>
You can help us by fixing red metro lines directly in OpenStreetMap. Then every [@OrganicMaps](https://t.me/OrganicMaps) user will have an updated Public Transport map (subways and S-Bahn at the moment).
Some general instructions are here:
<https://wiki.openstreetmap.org/wiki/Metro%5FMapping>
And here is info how to validate a separate city:
<https://github.com/alexey-zakharenkov/subways/>

11
content/news/33/index.md Normal file
View file

@ -0,0 +1,11 @@
---
date: "2021-10-09T18:07:49+00:00"
---
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)
If you didn't click on coordinates before, then it should work.
Good news: the fix is already on it's way into app stores! After updating to the latest 21.10.09 version everything will work back again.
Here is the fixed Google Play apk which can be installed manually (the same as is waiting for review now): <https://t.me/organicmaps/8486> or <https://cdn.organicmaps.app/apk/21100902-Google.apk>

BIN
content/news/34/1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

18
content/news/34/index.md Normal file
View file

@ -0,0 +1,18 @@
---
date: "2021-10-14T06:14:09+00:00"
---
A new app update is available!
* New OSM maps data as of 02.10.2021
* Added healthcare=laboratory type
* Fixed some map icons and their visibility
* Fixed rare routing crash
* Fixed junction, building=hotel, power=substation, railway=subway, tourism=artwork types
* Fixed missing addresses for some buildings
* Minor localization fixes
Also for Android:
* Editable Facebook, Instagram, Twitter and VK links for places
* Copy OSM and Open Location Code coordinates links
* Fixed black screen on PowerVR Rogue G6110 chips

11
content/news/35/index.md Normal file
View file

@ -0,0 +1,11 @@
---
date: "2021-10-21T09:36:45+00:00"
---
In 21.10.15 Google Play update we:
* Fixed crash for Public Routing in some cities
* Added workaround for the nasty Android 11 layout bug when the bottom toolbar was screwed up
* Fixed some translations
* barrier=swing\_gate is now visible on the map
Fdroid is not ready yet, stay tuned.

7
content/news/36/index.md Normal file
View file

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

12
content/news/37/index.md Normal file
View file

@ -0,0 +1,12 @@
---
date: "2021-11-09T22:05:28+00:00"
---
Meet November 4 Organic Maps update!
* New OSM maps data as of October 22
* Added mountain saddle, mountain pass, silo, storage tank, chain barrier, swing gate map types
* Fixed some icons and translations
🤖 Android-only:
* Moved❓Help dialog on the main toolbar for a better new user experience, and to avoid negative feedback from non-geeks. We'll add news there too!
* APK now has x86\_64 arch for Chromebooks and some old Intel Atom devices

BIN
content/news/38/1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

5
content/news/38/index.md Normal file
View file

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

5
content/news/40/index.md Normal file
View file

@ -0,0 +1,5 @@
---
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/>

21
content/news/41/index.md Normal file
View file

@ -0,0 +1,21 @@
---
date: "2021-12-03T22:18:34+00:00"
---
Meet Organic Maps app update 21.12.01
🤖 \+ 🍏
* New OSM maps data as of November 22
* Fixed routing between map regions, please test and report to us any issues!
* Type "water" or "drinking water" in search to find it around yourself
* Updated Russian, Finnish, German, French, Spanish, Ukrainian, Belarusian and Chinese translations
🤖 Android:
* Long tap on a POI/bookmark name/address to copy them into clipboard
* Reworked opening hours UI
* Restored "maps update is available" indicator
* Added LINE contacts to the place page
* Reduced APK size
* Updated Vulkan driver libraries
 iOS:
* Fixed opening of <https://omaps.app/> and om:// links on the cold start

24
content/news/42/index.md Normal file
View file

@ -0,0 +1,24 @@
---
date: "2022-01-14T14:44:07+00:00"
---
Meet new January Organic Maps app update, with many improvements from our beloved contributors 🙏!
* New OSM maps data as of January 3, 2022
* Improved search results ranking
* Fixed hundreds of "capitals" on the World map
* Fixed some invalid inter-region routes (more fixes in the next update!)
* Search recognizes rd/st/ct=road/street/court synonyms
* Consistent naming for Bookmark Lists
* Updated German, Italian, Romanian, Russian, Ukrainian, Turkish translations
* Added incomplete Hebrew and Swahili translations
Also for Android:
* Duck played music when announcing directions
* Copy most of the POI info using a long tap
* Fix non-working FAQ on Android 5 and 6
* Added Bulgarian translation
Also for iOS:
* Added Belarusian and Persian translations
* Slightly changed Find map in Download Maps dialog

7
content/news/43/index.md Normal file
View file

@ -0,0 +1,7 @@
---
date: "2022-01-15T13:08:26+00:00"
---
There is a regression with KML import on Android. No worries, the fix is already in review.
Update: its already available as of January 16.

5
content/news/44/index.md Normal file
View file

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

5
content/news/45/index.md Normal file
View file

@ -0,0 +1,5 @@
---
date: "2022-01-23T22:52:04+00:00"
---
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/>

6
content/news/46/index.md Normal file
View file

@ -0,0 +1,6 @@
---
date: "2022-02-02T11:26:11+00:00"
---
We've created a Telegram group for Turkish users, moderated by [@MetehanOzyurek](https://t.me/MetehanOzyurek)
Join [@OrganicMapsTR](https://t.me/OrganicMapsTR) or [use](https://t.me/OrganicMapsTR) [this](https://t.me/OrganicMapsTR) [link](https://t.me/OrganicMapsTR).

BIN
content/news/6/1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

10
content/news/6/index.md Normal file
View file

@ -0,0 +1,10 @@
---
date: "2021-05-06T07:20:28+00:00"
---
No more trackers according to the latest Exodus Privacy Report!
<https://reports.exodus-privacy.eu.org/en/reports/176462/>
Google Play: <https://play.google.com/store/apps/details?id=app.omaps>
App Store: <https://testflight.apple.com/join/62l4Qh2K>

21
content/news/7/index.md Normal file
View file

@ -0,0 +1,21 @@
---
date: "2021-05-09T08:00:03+00:00"
---
A new version 2021-05-08 is availiable for iOS and Android.
This update fixes several bugs and includes the latest May data.
**iOS**:
\- Fix a crash in bookmarks
Install from TestFlight: <https://testflight.apple.com/join/62l4Qh2K>
**Android**:
\- Fix a crash in Settings.
\- Fix random crashes in the background.
Get it on Google Play (Beta) - <https://play.google.com/store/apps/details?id=app.omaps>
Download APK from GitHub - <https://github.com/organicmaps/organicmaps/releases/tag/2021-05-08>

21
content/news/8/index.md Normal file
View file

@ -0,0 +1,21 @@
---
date: "2021-05-24T07:03:54+00:00"
---
A new beta version 2021-05-21 is out.
The version contains bug fixes and stability improvements.
Please use updated links:
Android:
Google Play: <https://play.google.com/store/apps/details?id=app.organicmaps>
Huawei AppGallery: <https://appgallery.huawei.com/#/app/C104325611>
GitHub APK: <https://github.com/organicmaps/organicmaps/releases/tag/2021-05-21>
Firebase APK: <https://appdistribution.firebase.dev/i/9ec3bca5e2b47373>
iOS:
Apple TestFlight: <https://testflight.apple.com/join/lrKCl08I>

BIN
content/news/9/1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

7
content/news/9/index.md Normal file
View file

@ -0,0 +1,7 @@
---
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/>

8
content/news/_index.md Normal file
View file

@ -0,0 +1,8 @@
---
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
sort_by: date
extra:
menu_title: News
---

View file

@ -188,3 +188,29 @@ footer {
overflow-x: auto;
white-space: nowrap;
}
.news_date {
display: flex;
flex-basis: 100%;
align-items: center;
margin: 1rem 0;
&:before, &:after {
content: "";
flex-grow: 1;
background-color: gray;
height: 1px;
font-size: 0px;
line-height: 0px;
margin: 0;
}
}
.news_image {
max-width: 80vw;
max-height: 480px;
margin-left: 0.5rem;
display: inline-block;
vertical-align: top;
}
.news_content {
display: inline-block;
}

View file

@ -1,6 +1,7 @@
<nav id="bottom_menu" role="navigation">
{% set home = get_section(path='_index.md') %}
{% for page in [home] | concat(with=home.pages) %}
{% set news = get_section(path='news/_index.md') %}
{% for page in [home, news] | concat(with=home.pages) %}
{% if page.extra.menu_title %}
{% if resource.path != page.path %}<a href="{{ page.path }}">{% endif %}
<span>{{ page.extra.menu_title }}</span>

View file

@ -1,9 +1,9 @@
<nav id="menu" role="navigation">
<span class="logo"></span>
<a href="/"><span class="logo"></span></a>
<span class="menu_items">
<span class="menuitem{% if resource.path != '/' %}"><a href="/">{% else %}_active">{% endif %}
<span>{{ trans(key='home') }}</span>
{%- if resource.path != '/' %}</a>{% endif %}
<span class="menuitem{% if resource.path != '/news/' %}"><a href="/news/">{% else %}_active">{% endif %}
<span>{{ trans(key='news') }}</span>
{%- if resource.path != '/news/' %}</a>{% endif %}
</span>
<span class="menuitem{% if resource.path != '/donate/' %}"><a href="/donate/">{% else %}_active">{% endif %}

15
templates/news.html Normal file
View file

@ -0,0 +1,15 @@
{% extends 'base.html' %}
{% block content %}
<h1>{{ resource.title }}</h1>
{% for post in resource.pages %}
<div class="news_date">&nbsp;{{ post.date | date(format='%B %e, %Y') }}&nbsp;</div>
<div class="news_content">{{ post.content | safe }}</div>
{% for photo in post.assets %}
<img class="news_image" src="{{ photo | safe }}" />
{% endfor %}
{% endfor %}
{% endblock content %}

105
update_news.js Normal file
View file

@ -0,0 +1,105 @@
// This script fetches Telegram channel preview and extracts content from it for our site.
'use strict';
const channelPreviewUrl = 'https://t.me/s/OrganicMapsApp';
const newsPath = `${__dirname}/content/news/`;
const https = require('https');
const parse = require('node-html-parser').parse;
const fs = require('fs');
const NodeHtmlMarkdown = require('node-html-markdown').NodeHtmlMarkdown;
const nhm = new NodeHtmlMarkdown();
const photoUrlRE = /url\(\'(.*?)\'/;
function downloadAsync(url, path) {
return new Promise((resolve, reject) => {
const request = https.get(url, res => {
if (res.statusCode != 200) return reject(new Error('statusCode=' + res.statusCode));
const filePath = fs.createWriteStream(path);
res.pipe(filePath);
filePath.on('finish', _ => {
filePath.close();
console.log('Downloaded ' + path);
resolve();
});
});
request.on('error', err => reject(err));
request.end();
}).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;
}
return frontmatter;
}
// 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();
function parseHtml(html) {
const root = parse(html);
// Skip service messages.
const messages = root.querySelectorAll('.tgme_widget_message:not(.service_message)');
console.log('Parsing ' + messages.length + ' Telegram posts.');
const downloads = [];
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');
const id = m.getAttribute('data-post').split('/').pop();
const dir = newsPath + id;
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
// Each message may have 0 or more photos.
for (let i = 1; i <= photos.length; ++i) {
let photo = photos[i - 1].getAttribute('style');
photo = photo.match(photoUrlRE)[1];
const ext = photo.split('.').pop();
const fileName = `${i}.${ext}`;
downloads.push(downloadAsync(photo, `${dir}/${fileName}`));
}
const markdown = toMarkdown(text, date);
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 });
}
});
}