Showing posts with label markdown. Show all posts
Showing posts with label markdown. Show all posts
Friday, 2 May 2025
Affinity-for-mermaid
A little aside from the [Mikrotik series](https://blog.themillhousegroup.com/search/label/mikrotik), but related.
As this blog series starts getting a little more involved I wanted to include some network diagrams. [Mermaid.js](https://mermaid.js.org/) has been [my choice for diagrams-as-markdown for ages now](https://blog.themillhousegroup.com/2023/10/markdown-and-mermaid-on-blogger-in-2023.html), and I noted that the new(ish) beta [architecture syntax](https://mermaid.js.org/syntax/architecture.html) would be a good fit.
Notably lacking however, was a nice suite of standard network diagram icons (routers, switches, firewalls, servers etc) to go with it.
A quick search led me to a Reddit question in [`r/networking`](https://www.reddit.com/r/networking/comments/108buv8/what_network_diagram_icons_is_everyone_using/?rdt=63267) where the [Affinity SVG set](https://github.com/ecceman/affinity) by [ecceman on GitHub]((https://github.com/ecceman) was [highly recommended](https://www.reddit.com/r/networking/comments/108buv8/comment/j3r8wxz/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button).
I liked the style, and the fact that the icons could be had "naked" as well as surrounded by circles or rounded squares (and in colour).
One [fork](https://github.com/themillhousegroup/affinity-for-mermaid) and some processing with [IconTools](https://iconify.design/docs/libraries/tools/import/directory.html) has led to a [Mermaid.js-compatible icon library](https://themillhousegroup.github.io/affinity-for-mermaid/), ready to consume with just a couple of extra lines of Mermaid configuration:
```
mermaid.registerIconPacks([{
name: 'affinity',
loader: () => fetch('https://themillhousegroup.github.io/affinity-for-mermaid/icons.json').then((res) => res.json()),
}]);
```
In addition to hosting the all-important JSON files, the GitHub pages also include [icon list](https://themillhousegroup.github.io/affinity-for-mermaid/demo.html) and [demo](https://themillhousegroup.github.io/affinity-for-mermaid/demo.html) pages so you can see what's available:
I have plans to expand this list to show the circular and square variants (and fix up some of the naming inconsistencies therein) - I might even see if I can code up a live sandbox page too ...
But without any further ado, here's the Mermaid architecture description for wired part of my home network ...
```
architecture-beta
service internet(affinity:cloud)
group home(affinity:house)[Home]
group study[Study] in home
service ispr(affcircle:c-firewall) [ISP Router] in study
group mik(affcircle:c-router)[RB2011] in study
service gbe(affcircle:c-switch-blue)[GbE] in mik
service hun(affcircle:c-switch-green)[100Mbps] in mik
service pi(affcircle:c-server-blue)[Pi] in study
service nas(affcircle:c-nas-blue)[NAS] in study
service nuc(affcircle:c-server-green)[NUC] in study
service studywifi(affcircle:c-wireless-green)[WiFi AP] in study
group closet[Closet] in home
group closetap(affcircle:c-switch) [ClosetAP] in closet
service closetswitch(affcircle:c-switch-blue)[Switch] in closetap
service closetwifi(affinity:wifi)[WiFi] in closetap
service tv(affcircle:c-client-blue)[TV] in home
service ps4(affcircle:c-server-blue)[PS4] in home
service cc(affcircle:c-client-blue)[ChromeCast] in home
internet:B -- T:ispr
ispr:L -[GbE]- R:gbe
ispr:R -[GbE study to closet backbone]- L:closetswitch
gbe:L -- R:hun
junction huns in study
hun:L -- R:huns
huns:L -[100Mbps]- R:nuc
huns:B -[100Mbps]- T:studywifi
junction gbes in study
gbe:B -- T:gbes
gbes:L -[GbE]- R:pi
gbes:R -[GbE]- L:nas
junction avgear in home
closetswitch:B -[GbE]- T:avgear
avgear:L -- R:tv
avgear:B -- T:ps4
avgear:R -- L:cc
```
... and the corresponding diagram, which your browser is rendering as I've enhanced my [md-in-blogger](https://github.com/themillhousegroup/md-in-blogger) script as used by this blog:
```mermaid
architecture-beta
service internet(affinity:cloud)
group home(affinity:house)[Home]
group study[Study] in home
service ispr(affcircle:c-firewall) [ISP Router] in study
group mik(affcircle:c-router)[RB2011] in study
service gbe(affcircle:c-switch-blue)[GbE] in mik
service hun(affcircle:c-switch-green)[100Mbps] in mik
service pi(affcircle:c-server-blue)[Pi] in study
service nas(affcircle:c-nas-blue)[NAS] in study
service nuc(affcircle:c-server-green)[NUC] in study
service studywifi(affcircle:c-wireless-green)[WiFi AP] in study
group closet[Closet] in home
group closetap(affcircle:c-switch) [ClosetAP] in closet
service closetswitch(affcircle:c-switch-blue)[Switch] in closetap
service closetwifi(affinity:wifi)[WiFi] in closetap
service tv(affcircle:c-client-blue)[TV] in home
service ps4(affcircle:c-server-blue)[PS4] in home
service cc(affcircle:c-client-blue)[ChromeCast] in home
internet:B -- T:ispr
ispr:L -[GbE]- R:gbe
ispr:R -[GbE study to closet backbone]- L:closetswitch
gbe:L -- R:hun
junction huns in study
hun:L -- R:huns
huns:L -[100Mbps]- R:nuc
huns:B -[100Mbps]- T:studywifi
junction gbes in study
gbe:B -- T:gbes
gbes:L -[GbE]- R:pi
gbes:R -[GbE]- L:nas
junction avgear in home
closetswitch:B -[GbE]- T:avgear
avgear:L -- R:tv
avgear:B -- T:ps4
avgear:R -- L:cc
```
I won't lie, it took a fair bit of tweaking to get that to lay out properly (there's no way to hint or influence the layout at this stage unfortunately, so trial-and-error via the `T|R|B|L` specifier on edges, and the occasional superfluous [`junction`](https://mermaid.js.org/syntax/architecture.html#junctions) is the only option) - but I'm pretty happy with the result now.
Monday, 23 October 2023
Markdown (and Mermaid) on Blogger in 2023
Building on the fine work of [cs905s](href="https://github.com/cs905s/md-in-blogger") on GitHub, I wanted to Markdown-enable my own blog and thought the process could be brought up-to-date - seven years have passed after all, and _that_ work was in turn based on something from [2011](http://blog.chukhang.com/2011/09/markdown-in-blogger.html)!
Blogger has, slowly but surely, changed since those instructions were written, so at the very least, here's an updated guide on how to do it.
### Extra Goals
I had a couple of extra requirements over the previous solution, however.
- I want to write **my whole post** in [GitHub-flavoured Markdown](https://github.github.com/gfm/); I use it all day (for PR descriptions, in Slack, writing documentation) and I'm pretty sick of the verbosity of `BOO` compared to `**BOO**`!
- I also never want to have to type `&lt;` instead of `<` _ever again_ so I want the script to perform that replacement for me.
- I have fallen in love with [Mermaid](https://mermaid.js.org/) for Markdown-inspired/embedded diagrams and want them to _Just Work_ in my blog in the same way GitHub does it, with a ` ```mermaid ... ``` ` code fence
For a fairly-techy blog, just those changes, plus being able to use backticks and other speedups, _just like it's GitHub/Slack_ is really valuable to me.
Here's an example embedded Mermaid flowchart, just because I can now:
```mermaid
flowchart TD
A[Have Blogger-hosted Blog] -->|Configure Markdown| B(Write blog post)
B --> C{Has
markdown-enabled
label
?}
C -->|Yes| D[Render Markdown to HTML post body]
D --> E[Hide original Markdown area]
C -->|No| F[Leave post body untouched]
F --> G{Has
pre with class markdown
?}
G -->|Yes| H[Render pre to HTML]
E --> I{Has
pre with class mermaid
?}
H --> I
I --> |Yes| J[Render with Mermaid.js]
I --> |No| K[Done]
```
So once you've added a `markdown-enabled` **Label** on your post, the entire **blog post body** will be considered the Markdown source. I decided to "opt-in" like this as I've got a couple-of-hundred non-Markdown-annotated blog posts that I didn't really fancy going back and opting-out of. Well, actually I did try to automate this but lost data in the process, so aborted that little yak-shaving side-mission.
The script will also remove that particular label from the DOM so nobody will see that "load-bearing label" 😉.
The source is [here on GitHub](https://github.com/themillhousegroup/md-in-blogger), and I'll endeavour to keep it working well on the Blogger platform over time. Check the README for the step-by-step instructions if you want to Markdown-enable your own blog!
Labels:
blog,
blogging,
dev,
github,
hacking,
markdown,
markdown-enabled,
opensource,
productivity
Subscribe to:
Posts (Atom)