forked from google/docsy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds shortcode to include remote markdown file
Fixes google#1716
- Loading branch information
1 parent
eaba498
commit 91fe87a
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{{/* Fetch a remote markdown file and include it in the page. If the file has a frontmatter, define the marker of the frontmatter in the second parameter (defaults to "---"). If the content after the frontmatter includes the marker (for example, includes "---" as part of a markdown-formatted table) the content included will be incomplete. */}} | ||
{{ $url := .Get 0 }} | ||
{{ $marker := .Get 1 | default "---" }} | ||
|
||
{{/* Do not change the indentation of the following block */}} | ||
{{ with resources.GetRemote $url }} | ||
{{ with .Err }} | ||
{{ errorf "%s" . }} | ||
{{ else }} | ||
{{/* Test for frontmatter */}} | ||
{{ if hasPrefix .Content $marker }} | ||
{{ $split := split .Content $marker }} | ||
|
||
{{ with strings.Contains .Content $marker }} {{- warnf "Remote snippet includes frontmatter marker, content is truncated: %s" $url -}} | ||
{{ end }} | ||
|
||
{{/* Output stuff after the frontmatter if a frontmatter was detected. */}} | ||
{{- index $split 2 | markdownify | safeHTML -}} | ||
{{ else }} | ||
{{/* Output the content of the file if no frontmatter was detected. */}} | ||
{{- .Content | safeHTML -}} | ||
{{ end }} | ||
{{ end }} | ||
{{ else }} | ||
{{ errorf "Unable to get remote resource %q" $url }} | ||
{{ end }} |