night0721.xyz/layouts/shortcodes/getreadme.html

24 lines
742 B
HTML

{{ $repo := .Get "repo" }}
{{ $rootReadmeURL := printf "https://api.github.com/repos/night0721/%s/contents/README.md" $repo }}
{{ $githubDirReadmeURL := printf "https://api.github.com/repos/night0721/%s/contents/.github/README.md" $repo }}
{{ $response := getJSON $rootReadmeURL }}
{{ if not (isset $response "content") }}
{{ $response = getJSON $githubDirReadmeURL }}
{{ end }}
{{ with $response }}
{{ if isset . "content" }}
{{ $content := .content | base64Decode }}
{{ $markdown := $content | markdownify }}
<div class="readme-content">
{{ $markdown | safeHTML }}
</div>
{{ else }}
<p>Error fetching README from GitHub.</p>
{{ end }}
{{ else }}
<p>Error fetching data from GitHub API.</p>
{{ end }}