night0721.xyz/layouts/shortcodes/getreadme.html

23 lines
762 B
HTML

{{ $repo := .Get "repo" }}
{{ $rootReadmeURL := printf "https://api.github.com/repos/night0721/%s/contents/README.md" $repo }}
{{ $response := getJSON $rootReadmeURL }}
{{ $githubDirReadmeURL := printf "https://api.github.com/repos/night0721/%s/contents/.github/README.md" $repo }}
{{ if and (not $response) (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>No README found for the repository.</p>
{{ end }}
{{ else }}
<p>Error fetching README from GitHub.</p>
{{ end }}