A lightweight, responsive map integration for Micro.blog (and other Hugo-based sites) that automatically generates interactive markers based on a data file. It uses Leaflet.js and OpenStreetMap, so no API keys are required.
The ideas and implementation logic for this project were conceived by me, but as I am not a developer, the code itself was generated with the assistance of AI. While the tool works as intended for my use case, I cannot attest to the quality of the code, its optimization, or its security. Use this code at your own risk.
To use this in your Micro.blog design settings, ensure your files are organized as follows:
-
data/cities.yml: The list of locations, coordinates, and links. -
layouts/partials/microblog-map.html: The logic and script that renders the map.
Create a file in your Micro.blog design area at data/cities.yml and add your locations following this format:
- name: "Boston, USA"
slug: "boston"
lat: 42.3601
lon: -71.0589
url: "/categories/boston"
- name: "Porto, Portugal"
slug: "porto"
lat: 41.1579
lon: -8.6291
url: "/categories/porto"
Create a new template at layouts/partials/microblog-map.html and paste the code provided in this repository.
To make embedding easier, create a file at layouts/shortcodes/map.html:
<div id="categoryMap" style="width: 100%; height: 500px; border-radius: 12px; margin: 30px 0;"></div>
You need to load the Leaflet CSS and JavaScript.
-
Tiny Theme users: Add this to
layouts/partials/microhook-head.html. -
Other themes: Add this to your
head.htmlpartial or header template.
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
Add the following line to your footer to load the map logic:
-
Tiny Theme users: Add this to
layouts/partials/microhook-footer.html. -
Other themes: Add this to your
footer.htmlpartial.
{{/* Safety check: Only call the partial if Hugo can find the file.
This allows you to use the {{< map >}} shortcode in any post. */}}
{{ if templates.Exists "partials/microblog-map.html" }}
{{ partial "microblog-map.html" . }}
{{ end }}
Simply add the following shortcode to any post or page: {{< map >}}
Alternatively, you can still use the manual HTML div with the ID categoryMap if preferred.
The script specifically looks for an element with the ID categoryMap. If it doesn't find that element on a page, the script exits silently, ensuring your site remains fast. When it finds the ID, it pulls data from cities.yml and automatically centers the map to fit your markers.
MIT - Feel free to use and modify for your own blog!