Skip to content

Commit 044faf6

Browse files
committed
Initial implementation
1 parent 72abb2e commit 044faf6

File tree

5 files changed

+2950
-71
lines changed

5 files changed

+2950
-71
lines changed

.eleventy.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
// Example use for the demo plugin:
2-
// {{ 'Steph' | hello | safe }}
1+
const {makeConfig, makeCache} = require('@torchlight-api/torchlight-cli/lib/config')
2+
const torchlight = require('@torchlight-api/torchlight-cli/lib/torchlight.js').default
3+
const highlight = require('@torchlight-api/torchlight-cli/lib/commands/highlight.js').default
34

45
module.exports = (eleventyConfig, options) => {
5-
// Define defaults for your plugin config
6-
const defaults = {
7-
htmlTag: "h2",
8-
};
6+
eleventyConfig.on('afterBuild', () => {
7+
const config = makeConfig('')
98

10-
// You can create more than filters as a plugin, but here's an example
11-
eleventyConfig.addFilter("hello", (name) => {
12-
// Combine defaults with user defined options
13-
const { htmlTag } = {
14-
...defaults,
15-
...options,
16-
};
9+
if (!config.length) {
10+
config.token = process.env.TORCHLIGHT_TOKEN
11+
config.highlight.input = '_site'
12+
}
1713

18-
return `<${htmlTag}>Hello, ${name}!</${htmlTag}>`;
19-
});
20-
};
14+
const cache = makeCache(config)
15+
16+
torchlight.init(config, cache)
17+
highlight(torchlight)
18+
})
19+
}

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
2-
_site
2+
_site
3+
cache
4+
torchlight.config.js

README.md

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,62 @@
1-
## Eleventy Plugin Template
1+
# eleventy-plugin-torchlight
22

3-
> A starter environment for creating plugins for Eleventy (11ty).
3+
This is a plugin for the static site generator [Eleventy](https://11ty.dev) to syntax highlight your code blocks with [torchlight.dev](https://torchlight.dev).
44

5-
Fork this repo, or select "Use this template" to get started.
5+
## Prerequisites
66

7-
### Using this template
7+
To use this plugin you need to be registered on [torchlight.dev](https://torchlight.dev) and have obtained an API key.
88

9-
This template is setup to run a single page 11ty site for testing your plugin functionality. The build files are excluded from the final plugin package via `.npmignore`.
9+
## Installation
1010

11-
Your plugin functionality should live in/be exported from `.eleventy.js`. You will find a sample of creating a filter plugin in this template, including setting up a default config and merging user options.
12-
13-
**Be sure to update the `package.json` with your own details!**
14-
15-
### Testing your plugin
16-
17-
You can test your functionality within this project's local 11ty build by running `npm start`, but you'll also want to test it _as a plugin_.
18-
19-
From another local 11ty project, you can set the `require()` path relatively to your plugin's project directory, and then use it just as you would for a plugin coming from a package.
11+
```bash
12+
npm install eleventy-plugin-torchlight #or
13+
yarn add eleventy-plugin-torchlight
14+
```
2015

21-
Example, assuming you place all your repositories within the same parent directory:
16+
Then, include it in your `.eleventy.js` config file:
2217

2318
```js
24-
const pluginName = require("../plugin-directory");
19+
const torchlight = require('eleventy-plugin-torchlight');
2520

2621
module.exports = (eleventyConfig) => {
27-
eleventyConfig.addPlugin(pluginName, { optionName: 'if needed' );
22+
eleventyConfig.addPlugin(torchlight);
2823
};
2924
```
3025

31-
Then, run the project to test the plugin's functionality.
32-
33-
Note that making changes in the plugin source will likely require restarting the test project.
34-
35-
### Resources for creating an 11ty plugin
36-
37-
- Bryan Robinson's ["Create a Plugin with 11ty"](https://www.youtube.com/watch?v=aO-NFFKjnnE) demonstration on "Learn With Jason"
38-
39-
---
26+
## Configuration
4027

41-
**The following is a boilerplate for your final plugin README**.
28+
Run `npx torchlight init` to initialize a default torchlight config. If you don't create a config yourself this plugin assumes this defaults to match 11ty's
29+
defaults:
4230

43-
## Usage
44-
45-
Describe how to install your plugin, such as:
46-
47-
```bash
48-
npm install @scope/plugin-name
31+
```
32+
{
33+
token: process.env.TORCHLIGHT_TOKEN,
34+
highlight: {
35+
input: '_site'
36+
}
37+
}
4938
```
5039

51-
Then, include it in your `.eleventy.js` config file:
40+
> If you create a new config remember to update the config to match the input path of Eleventy!
5241
53-
```js
54-
const pluginName = require("@scope/plugin-name");
42+
To verify everything works you can run Eleventy like this to pass the token as environment variable:
5543

56-
module.exports = (eleventyConfig) => {
57-
eleventyConfig.addPlugin(pluginName);
58-
};
5944
```
45+
`TORCHLIGHT_TOKEN=your_token npm run start`
46+
```
47+
48+
Your code should now be highlighted.
6049

61-
## Config Options
50+
If you are for example using Netflify you can add the token via your site's settings so it's available during the build.
6251

63-
| Option | Type | Default |
64-
| ----------- | ---- | ------------- |
65-
| option name | type | default value |
52+
### Cache
6653

67-
## Config Examples
54+
Torchlight uses a cache to prevent highlighting code blocks that don't have changed.
55+
By default it uses a [file based cache](https://torchlight.dev/docs/clients/cli#cache) which created a directory called `cache`.
6856

69-
Show examples of likely configurations.
57+
Make sure you add this folder to your `.eleventyignore` file so it doesn't trigger rebuilds after highlighting your output files.
7058

7159
## Credits
7260

73-
Add credits if needed.
61+
Thanks to [@5t3ph](https://twitter.com/5t3ph) for her [eleventy-plugin-template](https://github.com/5t3ph/eleventy-plugin-template)
62+
and [Aaron Francis](https://twitter.com/aarondfrancis) for [Torchlight](https://torchlight.dev).

package.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "@scope/plugin-name",
3-
"version": "1.0.0",
4-
"description": "Description of plugin",
5-
"homepage": "",
2+
"name": "eleventy-plugin-torchlight",
3+
"version": "0.1.0",
4+
"description": "This plugin runs your HTML files through Torchlight.dev for syntax highlighting",
5+
"homepage": "https://github.com/timkley/eleventy-plugin-torchlight",
66
"main": ".eleventy.js",
77
"scripts": {
88
"start": "eleventy --serve",
@@ -11,7 +11,7 @@
1111
},
1212
"repository": {
1313
"type": "git",
14-
"url": "git+https://github.com/username/repo-name.git"
14+
"url": "git+https://github.com/timkley/eleventy-plugin-torchlight.git"
1515
},
1616
"keywords": [
1717
"11ty",
@@ -20,14 +20,17 @@
2020
"eleventy-plugin"
2121
],
2222
"author": {
23-
"name": "username",
24-
"url": "https://website.com"
23+
"name": "Tim Kleyersburg",
24+
"url": "https://www.tim-kleyersburg.de"
2525
},
2626
"license": "ISC",
2727
"bugs": {
28-
"url": "https://github.com/username/repo-name/issues"
28+
"url": "https://github.com/timkley/eleventy-plugin-torchlight/issues"
2929
},
3030
"devDependencies": {
3131
"@11ty/eleventy": "^0.11.1"
32+
},
33+
"dependencies": {
34+
"@torchlight-api/torchlight-cli": "^0.1.2"
3235
}
3336
}

0 commit comments

Comments
 (0)