Skip to content

Commit

Permalink
Merge branch 'master' into feature/2018-08-07-file-structure
Browse files Browse the repository at this point in the history
  • Loading branch information
fboes committed Aug 23, 2018
2 parents 0433c9c + 088e95e commit 5741ed2
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 13 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ Update
1. To find out if your Blogophon needs updating, run `npm outdated -g blogophon`.
2. Run `npm update -g blogophon` to update your local Blogophon installation to the latest stable release.

Feedback
--------

In case of issues or suggestions for the Blogophon consider using [Blogophon's issue board](https://github.com/fboes/blogophon/issues).

Status
-------

Expand Down
2 changes: 1 addition & 1 deletion htdocs/themes/default/templates/partials/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ <h3>{{#i18n}}Links{{/i18n}}</h3>
<ul>
<li><a href="{{config.basePath}}tagged/">{{#i18n}}All tags{{/i18n}}</a></li>
{{#if config.twitterAccount}}
<li><a href="http://twitter.com/{{config.twitterAccount}}" rel="me">{{#i18n}}Twitter feed{{/i18n}}</a></li>
<li><a href="https://twitter.com/{{config.twitterAccount}}" rel="me">{{#i18n}}Twitter feed{{/i18n}}</a></li>
{{/if}}
</ul>
</section>
Expand Down
2 changes: 1 addition & 1 deletion htdocs/themes/default/templates/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ <h1>
</div>
<footer class="meta">
{{#if ../config.twitterAccount}}
<p><a href="http://twitter.com/{{../config.twitterAccount}}" rel="me">{{#i18n}}Comment &amp; discuss on Twitter{{/i18n}}</a></p>
<p><a href="https://twitter.com/{{../config.twitterAccount}}" rel="me">{{#i18n}}Comment &amp; discuss on Twitter{{/i18n}}</a></p>
{{/if}}
{{#if meta.Modified}}
<p>{{#i18n}}Last modified{{/i18n}} <time datetime="{{dateFormat meta.Modified 'iso'}}" itemprop="dateModified" class="modified dt-updated">{{dateFormat meta.Modified 'locale' meta.Language}}</time></p>
Expand Down
14 changes: 10 additions & 4 deletions lib/helpers/webmentions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ const querystring = require('querystring');
* @see http://alistapart.com/article/webmentions-enabling-better-communication-on-the-internet
* @param {Boolean} useConsole [description]
* @param {String} ua [description]
* @param {Object} options Like `blacklist`
* @return {Object} [description]
*/
const webmentions = function(useConsole = false, ua = 'Blogophon\'s Webmention Adapter') {
const webmentions = function(useConsole = false, ua = 'Blogophon\'s Webmention Adapter', options = {}) {
const external = {};
const internal = {};

options.blacklist = options.blacklist || /[/.](wikipedia\.org|wikia\.com|steampowered\.com|github\.com)/;

/**
* Send Webmentions to all external URLs found in article
* @param {Post} post [description]
Expand Down Expand Up @@ -46,11 +49,14 @@ const webmentions = function(useConsole = false, ua = 'Blogophon\'s Webmention A
const links = post.html.match(/<(?:a|link)[^>]+href="(https?:\/\/[^"]+)"[^>]*>/g) || [];
links.forEach(function(all) {
if (!all.match(/(class|rel)="[^"]*nomention/)) {
externalUrls.push(all.replace(/^.*href="([^"]*)".*$/, '$1'));
let possibleUrl = all.replace(/^.*href="([^"]*)".*$/, '$1');
if (internal.isExternalUrl(possibleUrl)) {
externalUrls.push(possibleUrl);
}
}
});
}
externalUrls = externalUrls.filter(function(value, index, self) {
externalUrls = externalUrls.filter((value, index, self) => {
return self.indexOf(value) === index;
});
return externalUrls;
Expand All @@ -62,7 +68,7 @@ const webmentions = function(useConsole = false, ua = 'Blogophon\'s Webmention A
* @return {Boolean} [description]
*/
internal.isExternalUrl = function(url) {
return url.match(/^https?:\/\//);
return url.match(/^https?:\/\//) && (!options.blacklist || !url.match(options.blacklist));
};

/**
Expand Down
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"static site generator"
],
"devDependencies": {
"autoprefixer": "^9.0.0",
"autoprefixer": "^9.1.3",
"beepbeep": "^1.2.2",
"gulp": "^3.9.1",
"gulp-eslint": "^5.0.0",
Expand Down Expand Up @@ -60,7 +60,7 @@
"glob": "^7.0.5",
"gm": "^1.23.0",
"handlebars": "^4.0.11",
"inquirer": "^6.0.0",
"inquirer": "^6.2.0",
"inquirer-datepicker-prompt": "^0.4.2",
"js-yaml": "^3.11.0",
"marked": "^0.5.0",
Expand All @@ -78,6 +78,14 @@
},
"globals": {},
"rules": {
"arrow-parens": [
"error",
"always"
],
"arrow-body-style": [
"error",
"always"
],
"brace-style": 2,
"comma-dangle": [
2,
Expand Down
23 changes: 18 additions & 5 deletions test/webmentions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
const assert = require('assert');
const webmentions = require('../lib/helpers/webmentions')();

describe('Webmentions', function() {
it('should find external URLs', function() {
describe('Webmentions', () => {
it('should find external URLs', () => {
let externalUrls;

externalUrls = webmentions.findExternalLinks({});
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('Webmentions', function() {
//console.log(externalUrls);
});

it('should ignore some external URLs', function() {
it('should ignore some external URLs', () => {
let externalUrls;

externalUrls = webmentions.findExternalLinks({
Expand All @@ -92,6 +92,19 @@ describe('Webmentions', function() {
assert.equal(externalUrls[0], 'https://www.example.com/');
});

it('should ignore external URLs from the black list', () => {
let externalUrls;

externalUrls = webmentions.findExternalLinks({
meta: {
hasExternalLink: true,
Link: 'https://example.wikipedia.org/external2'
},
html: `I am a <a href="https://example.wikipedia.org/external">Link</a>.`
});
assert.equal(externalUrls.length, 0);
});

const discoverUrls = [
'https://webmention.rocks/test/1',
'https://webmention.rocks/test/2',
Expand Down Expand Up @@ -122,15 +135,15 @@ describe('Webmentions', function() {
this.timeout(10000);
webmentions
.sendMentions('https://3960.org/sandbox/webmention.php', [url])
.then(function() {
.then(() => {
// if (result >= 400) {
// result.forEach(function(r) {
// console.log(r, url);
// });
// }
assert.ok(true);
})
.catch(function() {
.catch(() => {
assert.ok(false);
})
.then(done, done)
Expand Down

0 comments on commit 5741ed2

Please sign in to comment.