-
-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: pdf shortcode (unstable) (#345)
- Loading branch information
Showing
2 changed files
with
30 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,21 @@ | ||
{{/* This utility is used to get the file path from absolute, relative path or URL. */}} | ||
|
||
{{- $path := .path -}} | ||
{{- $page := .page -}} | ||
|
||
{{- $isLocal := not (urls.Parse $path).Scheme -}} | ||
{{- $isPage := and (eq $page.Kind "page") (not $page.BundleType) -}} | ||
{{- $startsWithSlash := hasPrefix $path "/" -}} | ||
{{- $startsWithRelative := hasPrefix $path "../" -}} | ||
|
||
{{- if and $path $isLocal -}} | ||
{{- if $startsWithSlash -}} | ||
{{/* File under static directory */}} | ||
{{- $path = (relURL (strings.TrimPrefix "/" $path)) -}} | ||
{{- else if and $isPage (not $startsWithRelative) -}} | ||
{{/* File is a sibling to the individual page file */}} | ||
{{ $path = (printf "../%s" $path) }} | ||
{{- end -}} | ||
{{- end -}} | ||
|
||
{{- return $path -}} |
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,9 @@ | ||
{{/* Shortcode to include a PDF file in a page. */}} | ||
|
||
{{- $path := .Get 0 -}} | ||
{{- $url := partial "utils/file-path" (dict "page" .Page "path" $path) -}} | ||
|
||
|
||
<div class="hextra-pdf"> | ||
<iframe src="{{ $url | safeURL }}" width="100%" style="min-height: 32rem;" frameborder="0"></iframe> | ||
</div> |