Skip to content

Commit

Permalink
Enhances Nav button (#17)
Browse files Browse the repository at this point in the history
* display Prose nav button only if `_prose.yml` file exists
* display Edit button only for Markdown files
* fix https
  • Loading branch information
ArnaudLigny authored Nov 16, 2019
1 parent 6d43518 commit 648ce54
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "Edit in Prose",
"description": "Provides an \"Edit in Prose\" link from a hosted file on GitHub.",
"version": "1.3.0",
"version": "1.4.0",
"manifest_version": 2,
"author": "Tristen Brown",
"homepage_url": "http://prose.io",
"homepage_url": "https://prose.io",
"icons": {
"16": "icon16.png",
"48": "icon48.png",
Expand Down
44 changes: 28 additions & 16 deletions src/prose.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,44 @@
const repo = parts[1];
const branch = parts[3];
const path = parts.slice(4).join('/');
const configFilePath = 'https://github.com/' + user + '/' + repo + '/blob/master/_prose.yml';

// User test
if (!user || !/^\w[\w-]+$/.test(user)) {
return;
}

// Nav button
if (repo) {
const nav = document.querySelector('.hx_reponav');
const button = document.querySelector('#prose');
if (!button) {
const link = document.createElement('a');
link.id = 'prose';
link.innerHTML = '<span class="prose-icon"></span>Prose';
link.title = 'Open in Prose';
link.className = 'js-selected-navigation-item reponav-item';
link.rel = 'nofollow';
nav.appendChild(link);
link.href = 'http://prose.io/#' + user + '/' + repo + '/';
// Prose config file test
fetch(configFilePath).then(response => {
if (response.ok) {
// Display nav button
const nav = document.querySelector('.hx_reponav');
const button = document.querySelector('#prose');
if (!button) {
const link = document.createElement('a');
link.id = 'prose';
link.innerHTML = '<span class="prose-icon"></span>Prose';
link.title = 'Open in Prose';
link.className = 'js-selected-navigation-item reponav-item';
link.rel = 'nofollow';
nav.appendChild(link);
link.href = 'https://prose.io/#' + user + '/' + repo + '/';
}
} else {
throw new Error('Can\'t find "_prose.yml" file');
}
}
}).catch(err => console.log(err.message));

// Sha Test
// Sha test
if (/^[0-9a-f]{40}$/.test(branch)) {
return;
}

// Markdown file type test
if (!/\.markdown|mdown|mkdn|mkd|md$/i.test(path)) {
return;
}

// Edit button
const root = document.querySelector(rootClass);
if (!root) {
Expand All @@ -57,6 +69,6 @@
edit = link.firstChild;
group.insertBefore(link, group.firstChild);
}
edit.href = 'http://prose.io/#' + user + '/' + repo + '/edit/' + branch + '/' + path;
edit.href = 'https://prose.io/#' + user + '/' + repo + '/edit/' + branch + '/' + path;
}
})();

0 comments on commit 648ce54

Please sign in to comment.