@11tyrocks/eleventy-plugin-emoji-readtime 中文文档教程

发布于 4年前 浏览 18 项目主页 更新于 3年前

Eleventy Plugin: Emoji Read Time

显示 Eleventy 内容的估计阅读时间,可选择使用表情符号视觉指示器。

To Use

这个插件提供了一个过滤器,可以通过传入 Eleventy 提供的 content 变量来应用,该变量最适合内容使用的布局。 返回一个简单的字符串,因此文本格式由您决定。

首先,在您的项目中安装插件:

npm install @11tyrocks/eleventy-plugin-emoji-readtime

然后,将其包含在您的 .eleventy.js 配置文件中:

const emojiReadTime = require("@11tyrocks/eleventy-plugin-emoji-readtime");

module.exports = (eleventyConfig) => {
  eleventyConfig.addPlugin(emojiReadTime);
};

*查看下面的配置选项和示例以了解如何修改输出

最后,将它作为过滤器添加到 content 中,无论您希望它显示在何处:

<p>{{ content | emojiReadTime }}</p>

默认输出示例:

7 min. read

Config Options

OptionTypeDefault
wpmnumber275
showEmojibooleantrue
emojistring????
labelstringmin. read
bucketSizenumber5

Config Examples

更改正在使用的表情符号、每分钟字数 (wpm)、标签和bucketSize,其中 bucketSize 是分钟除以决定要显示多少个表情符号:

eleventyConfig.addPlugin(emojiReadTime, {
  emoji: "????",
  label: "mins",
  wpm: 300,
  bucketSize: 3,
});

哪个会输出:

????7 mins

Remove emoji from being displayed

或者,删除表情符号,只显示分钟数和一个标签:

eleventyConfig.addPlugin(emojiReadTime, { showEmoji: false });

Credits

Eleventy Plugin: Emoji Read Time

Display an estimated read time for Eleventy content, optionally with an emoji visual indicator.

To Use

This plugin provides a filter that can be applied by passing in the Eleventy-supplied content variable, which work best from the layout used by the content. A simple string is returned, so the text formatting is up to you.

First, install the plugin in your project:

npm install @11tyrocks/eleventy-plugin-emoji-readtime

Then, include it in your .eleventy.js config file:

const emojiReadTime = require("@11tyrocks/eleventy-plugin-emoji-readtime");

module.exports = (eleventyConfig) => {
  eleventyConfig.addPlugin(emojiReadTime);
};

*Review config options and examples below for how to modify the output

Finally, add it as a filter to content wherever you'd like it to display:

<p>{{ content | emojiReadTime }}</p>

Example output with defaults:

???? 7 min. read

Config Options

OptionTypeDefault
wpmnumber275
showEmojibooleantrue
emojistring????
labelstringmin. read
bucketSizenumber5

Config Examples

Change the emoji in use, the words-per-minute (wpm), the label, and the bucketSize, where bucketSize is what minute is divided by to determine how many emoji to show:

eleventyConfig.addPlugin(emojiReadTime, {
  emoji: "????",
  label: "mins",
  wpm: 300,
  bucketSize: 3,
});

Which would output:

???????? 7 mins

Remove emoji from being displayed

Or, remove the emoji and only display the number of minutes and a label:

eleventyConfig.addPlugin(emojiReadTime, { showEmoji: false });

Credits

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文