Merge branch 'main' of https://github.com/nexeck/hugo-theme-relearn into nexeck-main

This commit is contained in:
Sören Weber 2023-07-31 16:18:12 +02:00
commit b7dfa81969
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
5 changed files with 233 additions and 186 deletions

View file

@ -598,3 +598,25 @@ timeline
2005 : Youtube
2006 : Twitter
{{< /mermaid >}}
### Sankey
````go
{{</* mermaid */>}}
sankey-beta
%% source,target,value
Electricity grid,Over generation / exports,104.453
Electricity grid,Heating and cooling - homes,113.726
Electricity grid,H2 conversion,27.14
{{</* /mermaid */>}}
````
{{< mermaid >}}
sankey-beta
%% source,target,value
Electricity grid,Over generation / exports,104.453
Electricity grid,Heating and cooling - homes,113.726
Electricity grid,H2 conversion,27.14
{{< /mermaid >}}

View file

@ -62,6 +62,7 @@
<script src="{{"js/d3/d3-timer.min.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}" defer></script>
<script src="{{"js/d3/d3-transition.min.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}" defer></script>
<script src="{{"js/d3/d3-zoom.min.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}" defer></script>
<script src="{{"js/js-yaml.min.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}" defer></script>
{{- if isset .Params "custommermaidurl" }}
<script src="{{ .Params.customMermaidURL }}" defer></script>
{{- else if isset .Site.Params "custommermaidurl" }}

2
static/js/js-yaml.min.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -166,11 +166,11 @@ function initMermaid( update, attrs ) {
var GRAPH=3;
var d = /^(?:\s*[\n\r])*(-{3}\s*[\n\r](?:.*?)[\n\r]-{3}(?:\s*[\n\r]+)+)?(?:\s*(?:%%\s*\{\s*\w+\s*:([^%]*?)%%\s*[\n\r]?))?(.*)$/s
var m = d.exec( graph );
var yaml = '';
var yaml = {};
var dir = {};
var content = graph;
if( m && m.length == 4 ){
yaml = m[YAML] ? m[YAML] : yaml;
yaml = m[YAML] ? jsyaml.load(m[YAML].replaceAll("---", "")) : yaml;
dir = m[INIT] ? JSON.parse( '{ "init": ' + m[INIT] ).init : dir;
content = m[GRAPH] ? m[GRAPH] : content;
}
@ -179,8 +179,10 @@ function initMermaid( update, attrs ) {
};
var serializeGraph = function( graph ){
var s = graph.yaml + '%%{init: ' + JSON.stringify( graph.dir ) + '}%%\n' + graph.content;
return s;
if (JSON.stringify(graph.dir) === '{}') {
return '---\n' + jsyaml.dump(graph.yaml) + '---\n' + graph.content;
}
return '---\n' + jsyaml.dump(graph.yaml) + '---\n' + '%%{init: ' + JSON.stringify(graph.dir) + '}%%\n' + graph.content;
};
var init_func = function( attrs ){
@ -189,11 +191,20 @@ function initMermaid( update, attrs ) {
document.querySelectorAll('.mermaid').forEach( function( element ){
var parse = parseGraph( decodeHTML( element.innerHTML ) );
if( parse.dir.theme ){
parse.dir.relearn_user_theme = true;
}
if( !parse.dir.relearn_user_theme ){
parse.dir.theme = theme;
if( JSON.stringify(parse.dir) === '{}' ){
if( parse.yaml.theme ){
parse.yaml.relearn_user_theme = true;
}
if( !parse.yaml.relearn_user_theme ){
parse.yaml.theme = theme;
}
} else {
if( parse.dir.theme ){
parse.dir.relearn_user_theme = true;
}
if( !parse.dir.relearn_user_theme ){
parse.dir.theme = theme;
}
}
is_initialized = true;
@ -215,10 +226,10 @@ function initMermaid( update, attrs ) {
var code = e.querySelector( '.mermaid-code' );
var parse = parseGraph( decodeHTML( code.innerHTML ) );
if( parse.dir.relearn_user_theme ){
if( parse.dir.relearn_user_theme || parse.yaml.relearn_user_theme ){
return;
}
if( parse.dir.theme == theme ){
if( parse.dir.theme == theme || parse.yaml.theme == theme ){
return;
}
is_initialized = true;