@11tyrocks/eleventy-plugin-open-in-codepen 中文文档教程

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

Eleventy Plugin: "Open in Codepen"

为代码演示添加“在 CodePen 中打开”功能的 Eleventy 简码。

Usage

首先,安装包:

npm install @11tyrocks/eleventy-plugin-open-in-codepen

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

const openInCodepen = require("@11tyrocks/eleventy-plugin-open-in-codepen");

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

要使用短代码,请传递包含 title的预期属性slugcsshtml

在模板的上下文中,slug 等同于 Eleventy 提供的 page.url 变量。

您可以使用模板语言功能为 csshtml 设置变量。 例如,Nunjucks 的 {% set css %}[CSS code]{% endset %}

{% postToCodepen "Pen Title", page.url, css, html %}

有关包含如何设置所需演示数据的扩展示例,请查看此 11ty Rocks 教程

Config Options

OptionTypeDefault
siteUrlstringhttps://codesampledomain.dev
siteTitlestringExample Site
siteTagstringcodesampledomain
buttonTextstringOpen in CodePen
buttonClassstringopen-in-codepen-button
buttonIconClassstringopen-in-codepen-icon
preDemoCSSstringsee below

默认的 preDemoCSS 是 Andy Bell 的Modern CSS reset 的缩减示例:

/* Box sizing rules */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Remove default margin */
body,
h1,
h2,
h3,
h4,
p {
  margin: 0;
}

/* Set core body defaults */
body {
  min-height: 100vh;
  text-rendering: optimizeSpeed;
  line-height: 1.5;
  font-family: system-ui, sans-serif;
}

/* Make images easier to work with */
img {
  display: block;
  max-width: 100%;
}

Config Example

这里是添加带有配置选项集的插件的示例:

eleventyConfig.addPlugin(openInCodepen, {
  siteUrl: "YourSite.dev",
  siteTitle: "Your Site",
  siteTag: "yoursite",
  buttonClass: "your-button-class",
  buttonIconClass: "your-button-icon-class",
});

Eleventy Plugin: "Open in Codepen"

An Eleventy shortcode to add "Open in CodePen" functionality for code demos.

Usage

First, install the package:

npm install @11tyrocks/eleventy-plugin-open-in-codepen

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

const openInCodepen = require("@11tyrocks/eleventy-plugin-open-in-codepen");

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

To use the shortcode, pass the expected properties inclusive of a title, slug, css, and html.

Within the context of a template, the slug is equivalent to the Eleventy provided page.url variable.

You can use the templating language abilities to set the variabls for css and html. For example {% set css %}[CSS code]{% endset %} for Nunjucks.

{% postToCodepen "Pen Title", page.url, css, html %}

For an extended example that includes how you might go about setting up the required demo data, review this 11ty Rocks tutorial.

Config Options

OptionTypeDefault
siteUrlstringhttps://codesampledomain.dev
siteTitlestringExample Site
siteTagstringcodesampledomain
buttonTextstringOpen in CodePen
buttonClassstringopen-in-codepen-button
buttonIconClassstringopen-in-codepen-icon
preDemoCSSstringsee below

The default preDemoCSS is a reduced sample from Andy Bell's Modern CSS reset:

/* Box sizing rules */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Remove default margin */
body,
h1,
h2,
h3,
h4,
p {
  margin: 0;
}

/* Set core body defaults */
body {
  min-height: 100vh;
  text-rendering: optimizeSpeed;
  line-height: 1.5;
  font-family: system-ui, sans-serif;
}

/* Make images easier to work with */
img {
  display: block;
  max-width: 100%;
}

Config Example

Here's an example of adding the plugin with config options set:

eleventyConfig.addPlugin(openInCodepen, {
  siteUrl: "YourSite.dev",
  siteTitle: "Your Site",
  siteTag: "yoursite",
  buttonClass: "your-button-class",
  buttonIconClass: "your-button-icon-class",
});
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文