Skip to content

Toward an Eleventy Plugin#74

Merged
kriskowal merged 5 commits intomainfrom
kriskowal-11ty
Dec 29, 2025
Merged

Toward an Eleventy Plugin#74
kriskowal merged 5 commits intomainfrom
kriskowal-11ty

Conversation

@kriskowal
Copy link
Member

@kriskowal kriskowal commented Dec 29, 2025

  • Parameterizes the page turn behavior
  • (Incidentally making a breaking change to the Document constructor, so bump major)
  • Adopts the hyperlink convention from Peruacru, e.g., {Example https://example.com}
  • Fixes timing of end hook, so the hook and react to the new frame displayed.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR parameterizes page turn behavior and adopts a hyperlink convention (e.g., {Example https://example.com}), making a breaking change to the Document constructor that requires a major version bump.

  • Refactors Document constructor to accept an options object instead of positional parameters
  • Implements automatic hyperlink detection and creation for URLs at the end of text
  • Adds configurable page turn behavior with 'log', 'remove', and 'fade' options

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
entry.js Updates Document instantiation to use new options-based constructor with pageTurnBehavior set to 'fade'
engine.js Moves display() call before handler.end() to ensure proper display timing at story end
document.js Refactors constructor to accept options object, implements hyperlink convention with regex matching, and parameterizes page turn behavior in clear() method

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +54 to +66
// TODO merge with prior text node
this.cursor.appendChild(document.createTextNode(lift + text));
} else {
// Support a hyperlink convention.
if (lift !== '') {
this.cursor.appendChild(document.createTextNode(lift));
}
const link = document.createElement('a');
link.href = match[1];
link.target = '_blank';
link.rel = 'noreferrer';
link.appendChild(document.createTextNode(text.slice(0, match.index)));
this.cursor.appendChild(link);
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation: this block uses 4 spaces while the rest of the file appears to use 2 spaces. Maintain consistent indentation throughout the file.

Suggested change
// TODO merge with prior text node
this.cursor.appendChild(document.createTextNode(lift + text));
} else {
// Support a hyperlink convention.
if (lift !== '') {
this.cursor.appendChild(document.createTextNode(lift));
}
const link = document.createElement('a');
link.href = match[1];
link.target = '_blank';
link.rel = 'noreferrer';
link.appendChild(document.createTextNode(text.slice(0, match.index)));
this.cursor.appendChild(link);
// TODO merge with prior text node
this.cursor.appendChild(document.createTextNode(lift + text));
} else {
// Support a hyperlink convention.
if (lift !== '') {
this.cursor.appendChild(document.createTextNode(lift));
}
const link = document.createElement('a');
link.href = match[1];
link.target = '_blank';
link.rel = 'noreferrer';
link.appendChild(document.createTextNode(text.slice(0, match.index)));
this.cursor.appendChild(link);

Copilot uses AI. Check for mistakes.
if (lift !== '') {
this.cursor.appendChild(document.createTextNode(lift));
}
const link = document.createElement('a');
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 'const' or 'let' instead of 'var' for the link variable declaration. Using 'var' is inconsistent with modern JavaScript best practices and can lead to unexpected scoping behavior.

Copilot uses AI. Check for mistakes.
this.frame.style.transform = 'translateX(-2ex)';
this.frame.addEventListener('transitionend', this);
if (this.pageTurnBehavior === 'log') {
this.options.remove();
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case 'log' appears to reference 'this.options.remove()' but should reference 'this.frame.remove()'. The 'log' behavior seems intended to keep previous pages in the document (for logging), but currently it only removes the options element, not handling the entire frame appropriately. This likely causes a bug where frames accumulate incorrectly.

Suggested change
this.options.remove();
this.frame.remove();

Copilot uses AI. Check for mistakes.
link.href = match[1];
link.target = '_blank';
link.rel = 'noreferrer';
link.appendChild(document.createTextNode(text.slice(0, match.index)));
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hyperlink implementation does not handle the case where the link text itself is empty (when match.index equals text.length). This would create an anchor element with no visible text, which is confusing for users and bad for accessibility.

Suggested change
link.appendChild(document.createTextNode(text.slice(0, match.index)));
const linkText = text.slice(0, match.index);
link.appendChild(document.createTextNode(linkText !== '' ? linkText : match[1]));

Copilot uses AI. Check for mistakes.
const link = document.createElement('a');
link.href = match[1];
link.target = '_blank';
link.rel = 'noreferrer';
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing 'noopener' in the rel attribute. When using target='_blank', it's a security best practice to include both 'noopener' and 'noreferrer' to prevent the new page from accessing the window.opener property and protect against potential security vulnerabilities.

Suggested change
link.rel = 'noreferrer';
link.rel = 'noreferrer noopener';

Copilot uses AI. Check for mistakes.
@kriskowal kriskowal merged commit b251f13 into main Dec 29, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants