Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New pathnameVersion issue-term type #568

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A lightweight comments widget built on GitHub issues. Use GitHub issues for blog

## how it works

When Utterances loads, the GitHub [issue search API](https://developer.github.com/v3/search/#search-issues) is used to find the issue associated with the page based on `url`, `pathname` or `title`. If we cannot find an issue that matches the page, no problem, [utterances-bot](https://github.com/utterances-bot) will automatically create an issue the first time someone comments.
When Utterances loads, the GitHub [issue search API](https://developer.github.com/v3/search/#search-issues) is used to find the issue associated with the page based on `url`, `pathname`, `pathnameVersion` or `title`. If we cannot find an issue that matches the page, no problem, [utterances-bot](https://github.com/utterances-bot) will automatically create an issue the first time someone comments.

To comment, users must authorize the utterances app to post on their behalf using the GitHub [OAuth flow](https://developer.github.com/v3/oauth/#web-application-flow). Alternatively, users can comment on the GitHub issue directly.

Expand Down
4 changes: 4 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const canonicalLink = document.querySelector(`link[rel='canonical']`) as HTMLLin
attrs.url = canonicalLink ? canonicalLink.href : location.origin + location.pathname + location.search;
attrs.origin = location.origin;
attrs.pathname = location.pathname.length < 2 ? 'index' : location.pathname.substr(1).replace(/\.\w+$/, '');
// Remove version segment to create pathnameVersion ( ex: v4.24/my/doc/page -> my/doc/page)
attrs.pathnameVersion = (attrs.pathname.split("/").length > 1) ?
attrs.pathname.split("/").slice(1).join("/") :
attrs.pathname;
attrs.title = document.title;
const descriptionMeta = document.querySelector(`meta[name='description']`) as HTMLMetaElement;
attrs.description = descriptionMeta ? descriptionMeta.content : '';
Expand Down
11 changes: 11 additions & 0 deletions src/configuration-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ export class ConfigurationComponent {
</p>
</label>
</div>
<div class="form-checkbox">
<label>
<input type="radio" value="pathnameVersion" name="mapping">
Issue title contains page pathname without version segment
<p class="note">
Utterances will search for an issue whose title contains the blog post's pathname
URL component, without version segment. If a matching issue is not found, Utterances will automatically
create one the first time someone comments on your post.
</p>
</label>
</div>
<div class="form-checkbox">
<label>
<input type="radio" value="url" name="mapping">
Expand Down
2 changes: 1 addition & 1 deletion src/page-attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function readPageAttributes() {
if (issueTerm === '') {
throw new Error('When issue-term is specified, it cannot be blank.');
}
if (['title', 'url', 'pathname', 'og:title'].indexOf(issueTerm) !== -1) {
if (['title', 'url', 'pathname', 'pathnameVersion', 'og:title'].indexOf(issueTerm) !== -1) {
if (!params[issueTerm]) {
throw new Error(`Unable to find "${issueTerm}" metadata.`);
}
Expand Down