A Hexo tag plugin for embedding link preview by OpenGraph on article.
npm install hexo-tag-ogp-link-previewA Hexo tag plugin for embedding link preview by OpenGraph on article.
``bash`
npm install hexo-tag-ogp-link-preview
Write like below to your hexo article markdown file:
``
{% link_preview url [target] [rel] [loading] [classSuffix] %}
[Content]
{% endlink_preview %}
or you are able to use "Named Parameter":
``
{% link_preview url [rel:{rel_value}] [target:{target_value}] [loading:{loading_value}] [classSuffix:{classSuffix_value}] %}
[Content]
{% endlink_preview %}
> [!NOTE]
> All optionally parameters (except for the required url parameter) are able to use "Named Parameter".
| Name | Required? | Default | Description |
|---------------|-----------|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| url | Yes | | This parameter is a target of the link preview. |target
| | No | _blank | Specify a target attribute of the anchor element._self
One of , _blank, _parent, or _top. |rel
| | No | nofollow | Specify a rel attribute of the anchor element.external
One of , nofollow, noopener, noreferrer, or opener. |loading
| | No | lazy | Specify a loading attribute of the image element.lazy
One of , eager, or none.none
If specify a , remove loading attribute from image element. |classSuffix
| | No | | Specify a suffix of class attribute value all of the div elements. |
content is fallback text which use when failed to get OpenGraph data from url.
You write like below to hexo configuration file _config.yml:
`yaml`
link_preview:
class_name:
anchor_link: link-preview
image: not-gallery-item
description_length: 140
disguise_crawler: true
> [!Note]
> All setting values are NOT required.
| Name | type | Default | Description |
|----------------------------|----------------------|----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| class_name | string or object | link-preview | If you are specified string, set a class attribute of the anchor element only.object
If you are specified , set each a class attribute of the anchor element and the image element. |class_name
| .anchor_link | string | link-preview | Set a class attribute of the anchor element. |class_name
| .image | string | | Set a class attribute of the image element.description_length
If you are not specify (empty string, etc.), nothing to set. |
| | number | 140 | It sliced to fit if a number of character of the og:Description exceeds the specified number value. |disguise_crawler
| | boolean | true | If scraper for OpenGraph want to disguise to crawler, set true.false
Otherwise, set to . |
Write a following to your hexo article markdown file:
`markdown`
{% link_preview https://www.example.com/ loading:lazy classSuffix:special %}
fallback Text
{% endlink_preview %}
When scraper get OpenGraph successfully, generated html like blow:
`html`

title text
description text
When scraper fail to get OpenGraph, generated html like blow:
`html``
fallback Text