Skip to content

Commit ba4d439

Browse files
authored
Merge pull request #15 from photogabble/release/v1.0.5
Release 1.0.5
2 parents 7c15657 + ab5cc2b commit ba4d439

File tree

7 files changed

+46
-22
lines changed

7 files changed

+46
-22
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.0.5]
11+
12+
- Change to use `url` instead of `inputPath` for unique page key, this is because some pages can share the same `inputPath` such as those generated via pagination.
13+
1014
## [1.0.4]
1115

1216
- Bugfix template `content` variable not being set when rendering embed (#10)

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,26 @@ Using the vertical bar (`|`) you can change the text used to display a link. Thi
7272

7373
Aliases provide you a way of referencing a file using different names, use the `aliases` property in your font matter to list one or more aliases that can be used to reference the file from a Wiki Link. For example, you might add _AI_ as an alias of a file titled _Artificial Intelligence_ which would then be linkable via `[[AI]]`.
7474

75+
### Linking to Pagination generated pages
76+
77+
A common use of pagination in 11ty is [pagination of an object](https://www.11ty.dev/docs/pagination/#paging-an-object) or data file, by default these generated pages aren't included in the all pages collection and therefore are invisible to this plugin unless you set `addAllPagesToCollections: true`.
78+
79+
Once done you will also need to set the title of each generated page so that this plugin can reference them, that can be done with `eleventyComputed` for example:
80+
81+
```yaml
82+
---
83+
pagination:
84+
data: collections.lists
85+
size: 1
86+
alias: list
87+
addAllPagesToCollections: true
88+
permalink: "{{ list.permalink }}"
89+
folder: lists
90+
eleventyComputed:
91+
title: "{{ list.title }}"
92+
---
93+
```
94+
7595
### Embedding
7696

7797
Embedding files allows you to reuse content across your website while tracking what pages have used it.

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = function (eleventyConfig, options = {}) {
3030
const wikilinkParser = new WikilinkParser(opts);
3131

3232
const compileTemplate = async (data) => {
33-
if (compiledEmbeds.has(data.inputPath)) return;
33+
if (compiledEmbeds.has(data.url)) return;
3434

3535
const frontMatter = data.template.frontMatter;
3636

@@ -51,7 +51,7 @@ module.exports = function (eleventyConfig, options = {}) {
5151
const fn = await rm.compile(tpl, language, {templateConfig, extensionMap});
5252
const result = await fn({content: frontMatter.content, ...data.data});
5353

54-
compiledEmbeds.set(data.inputPath, result);
54+
compiledEmbeds.set(data.url, result);
5555
}
5656

5757
let templateConfig;
@@ -107,14 +107,14 @@ module.exports = function (eleventyConfig, options = {}) {
107107
const currentSlug = opts.slugifyFn(data.title);
108108
let backlinks = [];
109109
let currentSlugs = new Set([currentSlug, data.page.fileSlug]);
110-
const currentPage = allPages.find(page => page.inputPath === data.page.inputPath);
110+
const currentPage = allPages.find(page => page.url === data.page.url);
111111

112112
// Populate our link map for use later in replacing WikiLinks with page permalinks.
113113
// Pages can list aliases in their front matter, if those exist we should map them
114114
// as well.
115115

116116
linkMapCache.set(currentSlug, {
117-
page: data.collections.all.find(page => page.inputPath === data.page.inputPath),
117+
page: data.collections.all.find(page => page.url === data.page.url),
118118
title: data.title
119119
});
120120

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@photogabble/eleventy-plugin-interlinker",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Obsidian WikiLinks, BackLinks and Embed support for 11ty",
55
"keywords": [
66
"11ty",

src/markdown-ext.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ const wikilinkRenderRule = (wikilinkParser, linkMapCache, compiledEmbeds, deadWi
6464
: '';
6565
}
6666

67-
const templateContent = compiledEmbeds.get(link.page.inputPath);
67+
const templateContent = compiledEmbeds.get(link.page.url);
6868
if (!templateContent) throw new Error(`WikiLink Embed found pointing to [${token.content}], has no compiled template.`);
6969

70-
return compiledEmbeds.get(link.page.inputPath);
70+
return compiledEmbeds.get(link.page.url);
7171
}
7272

7373
const anchor = {

tests/fixtures/multiline.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<p>This is a multiline file with <a href="/wiki-link">Wikilinks</a> and embeds to test that the inline rule works as expected.</p>
1+
<p>This is a multiline file with <a href="/wiki-link/">Wikilinks</a> and embeds to test that the inline rule works as expected.</p>
22
<p><div>Embed on its own</div></p>
33
<p>This paragraph includes an <span>inline embed</span> which could be used for embedding links and tracking their usage. Doing so is useful say you want to collect bookmarks and link those from multiple places and see usage.</p>
44
<blockquote>
5-
<p>This <a href="/wiki-link">Wiki Link</a> is inside a quote block.</p>
5+
<p>This <a href="/wiki-link/">Wiki Link</a> is inside a quote block.</p>
66
</blockquote>
77
<ul>
88
<li>Other</li>
99
<li>usage</li>
1010
<li>might be</li>
11-
<li>including a <a href="/wiki-link">Wiki Link</a> inside a list</li>
11+
<li>including a <a href="/wiki-link/">Wiki Link</a> inside a list</li>
1212
</ul>

tests/markdown-wikilink-renderer.test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test('inline rule correctly parses single wikilink', t => {
1515
linkMapCache.set('wiki-link', {
1616
title: 'Wiki Link',
1717
page: {
18-
url: '/wiki-link'
18+
url: '/wiki-link/'
1919
}
2020
});
2121

@@ -33,7 +33,7 @@ test('inline rule correctly parses single wikilink', t => {
3333
);
3434

3535
t.is(
36-
"<p>Hello world, this is some text with a <a href=\"/wiki-link\">Wiki Link</a> inside!</p>\n",
36+
"<p>Hello world, this is some text with a <a href=\"/wiki-link/\">Wiki Link</a> inside!</p>\n",
3737
md.render('Hello world, this is some text with a [[wiki link]] inside!', {})
3838
);
3939
});
@@ -46,14 +46,14 @@ test('inline rule correctly parses multiple wikilinks', t => {
4646
linkMapCache.set('wiki-link', {
4747
title: 'Wiki Link',
4848
page: {
49-
url: '/wiki-link'
49+
url: '/wiki-link/'
5050
}
5151
});
5252

5353
linkMapCache.set('another-wiki-link', {
5454
title: 'Another Wiki Link',
5555
page: {
56-
url: '/another-wiki-link'
56+
url: '/another-wiki-link/'
5757
}
5858
});
5959

@@ -71,7 +71,7 @@ test('inline rule correctly parses multiple wikilinks', t => {
7171
);
7272

7373
t.is(
74-
"<p>Hello world, this is some text with a <a href=\"/wiki-link\">Wiki Link</a> inside! There is also <a href=\"/another-wiki-link\">Another Wiki Link</a> in the same string.</p>\n",
74+
"<p>Hello world, this is some text with a <a href=\"/wiki-link/\">Wiki Link</a> inside! There is also <a href=\"/another-wiki-link/\">Another Wiki Link</a> in the same string.</p>\n",
7575
md.render('Hello world, this is some text with a [[wiki link]] inside! There is also [[another wiki link]] in the same string.', {})
7676
);
7777
});
@@ -85,11 +85,11 @@ test('inline rule correctly parses single embed', t => {
8585
title: 'Wiki Embed',
8686
page: {
8787
inputPath: '/src/wiki-embed.md',
88-
url: '/wiki-embed'
88+
url: '/wiki-embed/'
8989
}
9090
});
9191

92-
compiledEmbeds.set('/src/wiki-embed.md', '<span>Wiki Embed Test</span>');
92+
compiledEmbeds.set('/wiki-embed/', '<span>Wiki Embed Test</span>');
9393

9494
const md = require('markdown-it')({html: true});
9595
md.inline.ruler.push('inline_wikilink', wikilinkInlineRule(
@@ -119,28 +119,28 @@ test('inline rule correctly parses mixed wikilink and embed in multiline input',
119119
title: 'Inline Embed',
120120
page: {
121121
inputPath: '/src/inline-embed.md',
122-
url: '/inline-embed'
122+
url: '/inline-embed/'
123123
}
124124
});
125125

126126
linkMapCache.set('this-is-an-embed-on-its-own', {
127127
title: 'This is an embed on its own',
128128
page: {
129129
inputPath: '/src/lonely-embed.md',
130-
url: '/lonely-embed'
130+
url: '/lonely-embed/'
131131
}
132132
});
133133

134134
linkMapCache.set('wiki-link', {
135135
title: 'Wiki Link',
136136
page: {
137137
inputPath: '/src/wiki-link.md',
138-
url: '/wiki-link'
138+
url: '/wiki-link/'
139139
}
140140
});
141141

142-
compiledEmbeds.set('/src/inline-embed.md', '<span>inline embed</span>');
143-
compiledEmbeds.set('/src/lonely-embed.md', '<div>Embed on its own</div>');
142+
compiledEmbeds.set('/inline-embed/', '<span>inline embed</span>');
143+
compiledEmbeds.set('/lonely-embed/', '<div>Embed on its own</div>');
144144

145145
const md = require('markdown-it')({html: true});
146146
md.inline.ruler.push('inline_wikilink', wikilinkInlineRule(

0 commit comments

Comments
 (0)