11ty-to-codepen 中文文档教程

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

11ty-to-codepen

A simple 11ty shortcode for automagically creating pens on codepen!

Prerequisites

只有一个硬性要求(假设 eleventy 已经到位),那就是在 markdown 文件中允许 html。 Eleventy 默认为 html: false,这也是 markdown-it 库的默认值。

  • Make sure to enable it in your configuration!
  • Eg:
/* Markdown Overrides */
let markdownLibrary = markdownIt({
  html: true,
  breaks: true,
  linkify: true,
});
eleventyConfig.setLibrary("md", markdownLibrary);

Installation

安装应遵循通常的 NODE 舞蹈:

npm i -D 11ty-to-codepen

Usage

首先配置您的 .eleventy.js:

  • Import it:
// At the top of the file add:
const codepenIt = require("11ty-to-codepen");

// Somewhere before the final return add:
eleventyConfig.addPairedShortcode("codepen", codepenIt);
  • Use it in any .md file:
{% codepen "https://unpkg.com/bonsai.css@latest/dist/bonsai.min.css", "https://unpkg.com/uhtml", "Heyyy", "Waz uuuuuuuup", "Test it" %}

Some very important code:

```html
<h1 class="someClass">Test</h1>
```

```css
body {
  --mx: 4rem;
}
```

```js
var foo = function (bar) {
  return bar * 2;
};

console.log(foo(5));
```

{% endcodepen %}

Shortcode attributes:

codepen -> The shortcode (1st attr)

"https://unpkg.com/bonsai.css@latest/dist/bonsai.min.css", -> Any ext css (semicolon seperated) (2nd attr)

"https://unpkg.com/uhtml", -> Any ext js (semicolon seperated) (3rd attr)

"Heyyy", -> Title of the pen (4th attr)

"Waz uuuuuuuup", -> Description of the pen (5th attr)

"Test it" -> Button text (for i18n) (6th attr)

11ty-to-codepen

A simple 11ty shortcode for automagically creating pens on codepen!

Prerequisites

There is only one hard requirement (assuming that eleventy is already in place) and that is to allow html in the markdown files. Eleventy defaults to html: false which is also the default for the markdown-it Library.

  • Make sure to enable it in your configuration!
  • Eg:
/* Markdown Overrides */
let markdownLibrary = markdownIt({
  html: true,
  breaks: true,
  linkify: true,
});
eleventyConfig.setLibrary("md", markdownLibrary);

Installation

Installation should follow the usual NODE dance:

npm i -D 11ty-to-codepen

Usage

First configure your .eleventy.js:

  • Import it:
// At the top of the file add:
const codepenIt = require("11ty-to-codepen");

// Somewhere before the final return add:
eleventyConfig.addPairedShortcode("codepen", codepenIt);
  • Use it in any .md file:
{% codepen "https://unpkg.com/bonsai.css@latest/dist/bonsai.min.css", "https://unpkg.com/uhtml", "Heyyy", "Waz uuuuuuuup", "Test it" %}

Some very important code:

```html
<h1 class="someClass">Test</h1>
```

```css
body {
  --mx: 4rem;
}
```

```js
var foo = function (bar) {
  return bar * 2;
};

console.log(foo(5));
```

{% endcodepen %}

Shortcode attributes:

codepen -> The shortcode (1st attr)

"https://unpkg.com/bonsai.css@latest/dist/bonsai.min.css", -> Any ext css (semicolon seperated) (2nd attr)

"https://unpkg.com/uhtml", -> Any ext js (semicolon seperated) (3rd attr)

"Heyyy", -> Title of the pen (4th attr)

"Waz uuuuuuuup", -> Description of the pen (5th attr)

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