mirror of
https://github.com/nunocoracao/blowfish.git
synced 2026-01-30 16:31:52 +01:00
Merge pull request #2297 from ZhenShuo2021/feat/article-shortcode
✨ Feat: add options for article shortcode
This commit is contained in:
@@ -1028,6 +1028,12 @@ body.zen-mode-enable {
|
||||
height: 8px;
|
||||
}
|
||||
}
|
||||
.line-clamp-3 {
|
||||
overflow: hidden;
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 3;
|
||||
}
|
||||
.\!block {
|
||||
display: block !important;
|
||||
}
|
||||
@@ -1689,6 +1695,9 @@ body.zen-mode-enable {
|
||||
.p-1\.5 {
|
||||
padding: calc(var(--spacing) * 1.5);
|
||||
}
|
||||
.p-2\.5 {
|
||||
padding: calc(var(--spacing) * 2.5);
|
||||
}
|
||||
.p-4 {
|
||||
padding: calc(var(--spacing) * 4);
|
||||
}
|
||||
@@ -1758,6 +1767,9 @@ body.zen-mode-enable {
|
||||
.py-\[1px\] {
|
||||
padding-block: 1px;
|
||||
}
|
||||
.pt-1 {
|
||||
padding-top: calc(var(--spacing) * 1);
|
||||
}
|
||||
.pt-2 {
|
||||
padding-top: calc(var(--spacing) * 2);
|
||||
}
|
||||
@@ -1785,6 +1797,9 @@ body.zen-mode-enable {
|
||||
.pr-\[24px\] {
|
||||
padding-right: 24px;
|
||||
}
|
||||
.pb-0 {
|
||||
padding-bottom: calc(var(--spacing) * 0);
|
||||
}
|
||||
.pb-2 {
|
||||
padding-bottom: calc(var(--spacing) * 2);
|
||||
}
|
||||
@@ -1809,6 +1824,9 @@ body.zen-mode-enable {
|
||||
.pl-2 {
|
||||
padding-left: calc(var(--spacing) * 2);
|
||||
}
|
||||
.pl-4 {
|
||||
padding-left: calc(var(--spacing) * 4);
|
||||
}
|
||||
.pl-\[24px\] {
|
||||
padding-left: 24px;
|
||||
}
|
||||
|
||||
@@ -72,15 +72,17 @@ This is an error!
|
||||
| Parameter | Description |
|
||||
| --------- | -------------------------------------------------------- |
|
||||
| `link` | **Required.** the `.RelPermalink` to the target article. |
|
||||
| `showSummary` | **Optional.** A boolean value indicating whether to show the article summary. If not set, the site's default configuration will be used. |
|
||||
| `compactSummary` | **Optional.** A boolean value indicating whether to display the summary in compact mode. Default to false. |
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
**Example:**
|
||||
|
||||
```md
|
||||
{{</* article link="/docs/welcome/" */>}}
|
||||
{{</* article link="/it/docs/welcome/" showSummary=true compactSummary=true */>}}
|
||||
```
|
||||
|
||||
{{< article link="/docs/welcome/" >}}
|
||||
{{< article link="/it/docs/welcome/" showSummary=true compactSummary=true >}}
|
||||
|
||||
<br/><br/><br/>
|
||||
|
||||
|
||||
@@ -72,15 +72,17 @@ Twitter で私を[フォロー](https://twitter.com/nunocoracao)するのを忘
|
||||
| パラメータ | 説明 |
|
||||
| --------- | -------------------------------------------------------- |
|
||||
| `link` | **必須** ターゲット記事への `.RelPermalink`。 |
|
||||
| `showSummary` | **オプション** のブール値で、記事の要約を表示するかどうかを示します。設定されていない場合は、サイトのデフォルト設定が使用されます。 |
|
||||
| `compactSummary` | **オプション** のブール値で、要約をコンパクトモードで表示するかどうかを示します。デフォルトは false です。 |
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
**例:**
|
||||
|
||||
```md
|
||||
{{</* article link="/docs/welcome/" */>}}
|
||||
{{</* article link="/ja/docs/welcome/" showSummary=true compactSummary=true */>}}
|
||||
```
|
||||
|
||||
{{< article link="/docs/welcome/" >}}
|
||||
{{< article link="/ja/docs/welcome/" showSummary=true compactSummary=true >}}
|
||||
|
||||
<br/><br/><br/>
|
||||
|
||||
|
||||
@@ -72,15 +72,17 @@ This is an error!
|
||||
| Parameter | Description |
|
||||
| --------- | -------------------------------------------------------- |
|
||||
| `link` | **Required.** the `.RelPermalink` to the target article. |
|
||||
| `showSummary` | **Optional.** A boolean value indicating whether to show the article summary. If not set, the site's default configuration will be used. |
|
||||
| `compactSummary` | **Optional.** A boolean value indicating whether to display the summary in compact mode. Default to false. |
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
**Example:**
|
||||
|
||||
```md
|
||||
{{</* article link="/docs/welcome/" */>}}
|
||||
{{</* article link="/docs/welcome/" showSummary=true compactSummary=true */>}}
|
||||
```
|
||||
|
||||
{{< article link="/docs/welcome/" >}}
|
||||
{{< article link="/docs/welcome/" showSummary=true compactSummary=true >}}
|
||||
|
||||
<br/><br/><br/>
|
||||
|
||||
|
||||
@@ -72,15 +72,17 @@ This is an error!
|
||||
| 参数 | 功能 |
|
||||
| ------ | ------------------------------------- |
|
||||
| `link` | **必填** 要嵌入文章的 `.RelPermalink` |
|
||||
| `showSummary` | **可选** 布尔值,指示是否显示文章摘要。如果未设置,将使用站点的默认配置。 |
|
||||
| `compactSummary` | **可选** 布尔值,指示是否以紧凑模式显示摘要。默认为 false。 |
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
**例如:**
|
||||
|
||||
```md
|
||||
{{</* article link="/zh-cn/docs/welcome/" */>}}
|
||||
{{</* article link="/zh-cn/docs/welcome/" showSummary=true compactSummary=true */>}}
|
||||
```
|
||||
|
||||
{{< article link="/zh-cn/docs/welcome/" >}}
|
||||
{{< article link="/zh-cn/docs/welcome/" showSummary=true compactSummary=true >}}
|
||||
|
||||
<br/><br/><br/>
|
||||
|
||||
|
||||
120
layouts/partials/article-link/_shortcode.html
Normal file
120
layouts/partials/article-link/_shortcode.html
Normal file
@@ -0,0 +1,120 @@
|
||||
{{ $target := .target }}
|
||||
{{ $shortcodeShowSummary := .showSummary }}
|
||||
{{ $shortcodeCompactSummary := .compactSummary }}
|
||||
{{ $constrainItemsWidth := site.Params.list.constrainItemsWidth | default false }}
|
||||
{{ $disableImageOptimization := site.Params.disableImageOptimization | default false }}
|
||||
|
||||
{{ $articleClasses := "flex flex-wrap md:flex-nowrap article" }}
|
||||
{{ if site.Params.list.showCards }}
|
||||
{{ $articleClasses = delimit (slice $articleClasses "border border-neutral-200 dark:border-neutral-700 border-2 rounded-md overflow-hidden") " " }}
|
||||
{{ else }}
|
||||
{{ $articleClasses = delimit (slice $articleClasses "") " " }}
|
||||
{{ end }}
|
||||
|
||||
{{ $articleImageClasses := "w-full md:w-auto h-full thumbnail nozoom" }}
|
||||
{{ if site.Params.list.showCards }}
|
||||
{{ $articleImageClasses = delimit (slice $articleImageClasses "") " " }}
|
||||
{{ else }}
|
||||
{{ $articleImageClasses = delimit (slice $articleImageClasses "thumbnailshadow md:mr-7") " " }}
|
||||
{{ end }}
|
||||
|
||||
{{ $articleInnerClasses := "" }}
|
||||
{{ if site.Params.list.showCards }}
|
||||
{{ $articleInnerClasses = delimit (slice $articleInnerClasses "p-2.5 pl-4 pb-0") " " }}
|
||||
{{ else }}
|
||||
{{ $articleInnerClasses = delimit (slice $articleInnerClasses "mt-3 md:mt-0") " " }}
|
||||
{{ end }}
|
||||
|
||||
{{ if $constrainItemsWidth }}
|
||||
{{ $articleClasses = delimit (slice $articleClasses "max-w-prose") " " }}
|
||||
{{ end }}
|
||||
|
||||
|
||||
<a class="{{ $articleClasses }}" {{ partial "article-link/_external-link.html" . | safeHTMLAttr }}>
|
||||
{{- with $target.Params.images -}}
|
||||
{{- range first 6 . }}
|
||||
<meta property="og:image" content="{{ . | absURL }}">
|
||||
{{ end -}}
|
||||
{{- else -}}
|
||||
{{- $images := $target.Resources.ByType "image" -}}
|
||||
{{- $featured := $images.GetMatch "*feature*" -}}
|
||||
{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}}
|
||||
{{ if and $target.Params.featureimage (not $featured) }}
|
||||
{{- $url:= $target.Params.featureimage -}}
|
||||
{{ $featured = resources.GetRemote $url }}
|
||||
{{ end }}
|
||||
{{- if not $featured }}
|
||||
{{ with site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }}
|
||||
{{ end -}}
|
||||
{{ if $target.Params.hideFeatureImage }}{{ $featured = false }}{{ end }}
|
||||
{{- with $featured -}}
|
||||
{{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg") }}
|
||||
{{ with . }}
|
||||
<div class="{{ $articleImageClasses }}" style="background-image:url({{ .RelPermalink }});"></div>
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
{{ with .Resize "600x" }}
|
||||
<div class="{{ $articleImageClasses }}" style="background-image:url({{ .RelPermalink }});"></div>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{- else -}}
|
||||
{{- with site.Params.images }}
|
||||
<meta property="og:image" content="{{ index . 0 | absURL }}">
|
||||
{{ end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
|
||||
<div class="{{ $articleInnerClasses }}">
|
||||
<div class="items-center text-left text-xl font-semibold">
|
||||
{{ with $target.Params.externalUrl }}
|
||||
<div>
|
||||
<div
|
||||
class="decoration-primary-500 dark:text-neutral text-xl font-bold text-neutral-800 hover:underline hover:underline-offset-2">
|
||||
{{ $target.Title | emojify }}
|
||||
<span class="cursor-default align-top text-xs text-neutral-400 dark:text-neutral-500">
|
||||
<span class="rtl:hidden">↗</span>
|
||||
<span class="ltr:hidden">↖</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{{ else }}
|
||||
<div
|
||||
class="decoration-primary-500 dark:text-neutral text-xl font-bold text-neutral-800 hover:underline hover:underline-offset-2"
|
||||
href="{{ $target.RelPermalink }}">
|
||||
{{ $target.Title | emojify }}
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ if and $target.Draft site.Params.article.showDraftLabel }}
|
||||
<div class="ltr:ml-2 rtl:mr-2">
|
||||
{{ partial "badge.html" (i18n "article.draft" | emojify) }}
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ if templates.Exists "partials/extend-article-link.html" }}
|
||||
{{ partial "extend-article-link.html" $target }}
|
||||
{{ end }}
|
||||
</div>
|
||||
<div class="text-sm text-neutral-500 dark:text-neutral-400">
|
||||
{{ partial "article-meta/basic.html" $target }}
|
||||
</div>
|
||||
{{ $showSummary := false }}
|
||||
{{ if ne $shortcodeShowSummary nil }}
|
||||
{{ $showSummary = $shortcodeShowSummary }}
|
||||
{{ else }}
|
||||
{{ $showSummary = $target.Params.showSummary | default (site.Params.list.showSummary | default false) }}
|
||||
{{ end }}
|
||||
{{ if $showSummary }}
|
||||
{{ $compactSummary := false }}
|
||||
{{ if ne $shortcodeCompactSummary nil }}
|
||||
{{ $compactSummary = $shortcodeCompactSummary }}
|
||||
{{ else }}
|
||||
{{ $compactSummary = $target.Params.compactSummary | default (site.Params.list.compactSummary | default false) }}
|
||||
{{ end }}
|
||||
<div class="overflow-hidden pt-1">
|
||||
<div class="{{ if $compactSummary }}line-clamp-3{{ end }} max-w-fit prose dark:prose-invert">
|
||||
{{ $target.Summary | plainify }}
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
</a>
|
||||
@@ -1,10 +1,13 @@
|
||||
{{ $link := .Get "link" }}
|
||||
{{ $showSummary := .Get "showSummary" }}
|
||||
{{ $compactSummary := .Get "compactSummary" | default false }}
|
||||
{{ $target := .Page }}
|
||||
{{ if ne $link .Page.RelPermalink }}
|
||||
{{ $target = index (first 1 (where .Site.AllPages "RelPermalink" $link)) 0 }}
|
||||
{{ end }}
|
||||
{{ if $target }}
|
||||
<section class="space-y-10 w-full">
|
||||
{{ partial "article-link/simple.html" $target }}
|
||||
{{ $context := dict "target" $target "showSummary" $showSummary "compactSummary" $compactSummary }}
|
||||
{{ partial "article-link/_shortcode.html" $context }}
|
||||
</section>
|
||||
{{ end }}
|
||||
|
||||
Reference in New Issue
Block a user