From 840d907235d1a81b8ebfa0345f5e848452d69d60 Mon Sep 17 00:00:00 2001 From: randogoth Date: Tue, 2 May 2023 17:06:57 +0300 Subject: [PATCH] readme update --- README.md | 58 +++++----- geoblog/geoblog.py | 160 +++++++++++++-------------- templates/archives.html | 236 ++++++++++++++++++++-------------------- 3 files changed, 229 insertions(+), 225 deletions(-) diff --git a/README.md b/README.md index 6f93baa..c3be627 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,31 @@ -# GeoBlog Plugin - -This plugin scans for `Location: , ` metadata in articles and displays them on a map using the included `archives.html` template. It also writes `articles.gpx` and `articles.kml` files with the same information for offline GPS devices and Apps. - -## Installation - -Copy the `geoblog` folder to your local Pelican plug-ins folder and activate the plug-in in your `pelicanconf.py` file: - -``` -PLUGINS = ['geoblog'] -``` - -Copy the `archives.html` file to your Pelican theme's `templates` folder. - -If you want to use it for `categories` or other `index.html` derived template files, make sure to adjust the loop accordingly: - -``` -{% for article in articles %} -``` - -## Use - -Add location coordinates as decimal latitude and longitude values to your article metadata header. The map will display markers that show a pop up with the clickable title of the article when clicked. - -``` -Location: 12.009621864420991, 79.81141615530888 -``` \ No newline at end of file +# GeoBlog Pelican Plugin + +This plugin scans for `Location: , ` metadata in articles and displays them on a map using the included `archives.html` template. It also writes `articles.gpx` and `articles.kml` files with the same information for offline GPS devices and Apps. + +## Installation + +Copy the `geoblog` folder to your local Pelican plug-ins folder and activate the plug-in in your `pelicanconf.py` file: + +``` +PLUGINS = ['geoblog'] +``` + +Copy the `archives.html` file to your Pelican theme's `templates` folder. + +If you want to use it for `categories` or other `index.html` derived template files, make sure to adjust the loop accordingly: + +``` +{% for article in articles %} +``` + +## Use + +Add location coordinates as decimal latitude and longitude values to your article metadata header. The map will display markers that show a pop up with the clickable title of the article when clicked. + +``` +Location: 12.009621864420991, 79.81141615530888 +``` + +## Notes + +The generated map is based on [leaflet.js](https://leafletjs.com) and is highly customizable \ No newline at end of file diff --git a/geoblog/geoblog.py b/geoblog/geoblog.py index 85cb54b..b17cd31 100644 --- a/geoblog/geoblog.py +++ b/geoblog/geoblog.py @@ -1,81 +1,81 @@ -from pelican import signals -from xml.dom import minidom - -settings = {} -collection = {} -gpx_root = ''' -''' -kml_root = ''' -''' - -def init(self): - settings['files'] = self.settings.get('OUTPUT_PATH') - -def generate_latlon(generator): - for article in generator.articles: - if "location" in article.metadata: - lat, lon = [float(i) for i in article.metadata['location'].replace(' ', '').split(',')] - article.metadata['lat'] = lat - article.metadata['lon'] = lon - -def make_files(void): - print(collection) - makeGPX() - makeKML() - -def makeKML(): - if len(collection) > 0: - root = minidom.parseString(kml_root) - folder = root.createElement('name') - foldername = root.createTextNode( 'articles' ) - folder.appendChild( foldername ) - root.childNodes[0].childNodes[0].childNodes[0].appendChild( folder ) - for place in collection: - placemark = root.createElement('Placemark') - name = root.createElement('name') - title = root.createTextNode( collection[place]['name'] + ' (' + collection[place]['url'] +')') - name.appendChild( title ) - placemark.appendChild( name ) - point = root.createElement('Point') - coordinates = root.createElement('coordinates') - lat, lon = collection[place]['coordinates'].replace(' ', '').split(',') - latlon = root.createTextNode( lon + ',' + lat) - coordinates.appendChild( latlon ) - point.appendChild( coordinates ) - placemark.appendChild( point ) - root.childNodes[0].childNodes[0].childNodes[0].appendChild( placemark ) - with open(settings['files'] + '/articles.kml', 'w') as xml_file: - root.writexml(xml_file, indent="", addindent=" ", newl='\n') - -def makeGPX(): - if len(collection) > 0: - root = minidom.parseString(kml_root) - for place in collection: - lat, lon = collection[place]['coordinates'].replace(' ', '').split(',') - wpt = root.createElement('wpt') - wpt.setAttribute('lat', lat) - wpt.setAttribute('lon', lon) - name = root.createElement('name') - title = root.createTextNode( collection[place]['name'] + ' (' + collection[place]['url'] +')' ) - name.appendChild( title ) - wpt.appendChild( name ) - root.childNodes[0].appendChild( wpt ) - with open(settings['files'] + '/articles.gpx', 'w') as xml_file: - root.writexml(xml_file, indent="", addindent=" ", newl='\n') - -def geodata(generator): - for article in generator.articles: - if "location" in article.metadata: - collection.update({ - article.slug : { - "url" : generator.settings['SITEURL'] + '/' + article.url, - "name": article.title, - "coordinates": article.metadata["location"], - } - }) - -def register(): - signals.initialized.connect(init) - signals.article_generator_finalized.connect(generate_latlon) - signals.article_generator_finalized.connect(geodata) +from pelican import signals +from xml.dom import minidom + +settings = {} +collection = {} +gpx_root = ''' +''' +kml_root = ''' +''' + +def init(self): + settings['files'] = self.settings.get('OUTPUT_PATH') + +def generate_latlon(generator): + for article in generator.articles: + if "location" in article.metadata: + lat, lon = [float(i) for i in article.metadata['location'].replace(' ', '').split(',')] + article.metadata['lat'] = lat + article.metadata['lon'] = lon + +def make_files(void): + print(collection) + makeGPX() + makeKML() + +def makeKML(): + if len(collection) > 0: + root = minidom.parseString(kml_root) + folder = root.createElement('name') + foldername = root.createTextNode( 'articles' ) + folder.appendChild( foldername ) + root.childNodes[0].childNodes[0].childNodes[0].appendChild( folder ) + for place in collection: + placemark = root.createElement('Placemark') + name = root.createElement('name') + title = root.createTextNode( collection[place]['name'] + ' (' + collection[place]['url'] +')') + name.appendChild( title ) + placemark.appendChild( name ) + point = root.createElement('Point') + coordinates = root.createElement('coordinates') + lat, lon = collection[place]['coordinates'].replace(' ', '').split(',') + latlon = root.createTextNode( lon + ',' + lat) + coordinates.appendChild( latlon ) + point.appendChild( coordinates ) + placemark.appendChild( point ) + root.childNodes[0].childNodes[0].childNodes[0].appendChild( placemark ) + with open(settings['files'] + '/articles.kml', 'w') as xml_file: + root.writexml(xml_file, indent="", addindent=" ", newl='\n') + +def makeGPX(): + if len(collection) > 0: + root = minidom.parseString(kml_root) + for place in collection: + lat, lon = collection[place]['coordinates'].replace(' ', '').split(',') + wpt = root.createElement('wpt') + wpt.setAttribute('lat', lat) + wpt.setAttribute('lon', lon) + name = root.createElement('name') + title = root.createTextNode( collection[place]['name'] + ' (' + collection[place]['url'] +')' ) + name.appendChild( title ) + wpt.appendChild( name ) + root.childNodes[0].appendChild( wpt ) + with open(settings['files'] + '/articles.gpx', 'w') as xml_file: + root.writexml(xml_file, indent="", addindent=" ", newl='\n') + +def geodata(generator): + for article in generator.articles: + if "location" in article.metadata: + collection.update({ + article.slug : { + "url" : generator.settings['SITEURL'] + '/' + article.url, + "name": article.title, + "coordinates": article.metadata["location"], + } + }) + +def register(): + signals.initialized.connect(init) + signals.article_generator_finalized.connect(generate_latlon) + signals.article_generator_finalized.connect(geodata) signals.finalized.connect(make_files) \ No newline at end of file diff --git a/templates/archives.html b/templates/archives.html index 05cc1a2..134911a 100644 --- a/templates/archives.html +++ b/templates/archives.html @@ -1,118 +1,118 @@ - - - - - - - - {{ SITENAME }} - - - - - - - - - - -
- - - + + + + + + + + {{ SITENAME }} + + + + + + + + + + +
+ + +