From 71bb0e382abe470736081933a9c7186a3ce16e11 Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 1 May 2017 15:27:52 +0900 Subject: [PATCH 1/4] [general] support more icon pattern resolve #64. --- src/general.ts | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/general.ts b/src/general.ts index 67be1cf..84f8c85 100644 --- a/src/general.ts +++ b/src/general.ts @@ -70,31 +70,37 @@ export default async (url: URL.Url): Promise => { siteName = siteName ? entities.decode(siteName) : null; - let icon = + const favicon = $('link[rel="shortcut icon"]').attr('href') || - $('link[rel="icon"]').attr('href'); + $('link[rel="icon"]').attr('href') || + '/favicon.ico' - if (icon == null) { - const favicon = '/favicon.ico'; - - const foundFavicon = await new Promise(done => { - request.head(URL.resolve(url.href, favicon), (err, res) => { - if (err) { - done(false); - } else if (res.statusCode == 200) { - done(true); - } else { - done(false); - } - }); + const checkExistence = (checkURL: string): Promise => new Promise(done => { + request.head(checkURL, (err, res) => { + if (err) { + done(null); + } else if (res.statusCode == 200) { + done(checkURL); + } else { + done(null); + } }); + }); - if (foundFavicon) { - icon = favicon; - } + // 相対的なURL (ex. test) を絶対的 (ex. /test) に変換 + const toAbsolute = (relativeURLString: string): string => { + const relativeURL = URL.parse(relativeURLString); + const isAbsolute = relativeURL.slashes || relativeURL.path.indexOf("/") === 0; + // 既に絶対的なら、即座に値を返却 + if (isAbsolute) return relativeURLString; + // スラッシュを付けて返却 + return "/" + relativeURLString; } - icon = icon ? URL.resolve(url.href, icon) : null; + const icon = await checkExistence(URL.resolve(url.href, favicon)) || + // 相対指定を絶対指定に変換し再試行 + await checkExistence(URL.resolve(url.href, toAbsolute(favicon))) || + null if (/[\-—\|:]$/.test(title.replace(new RegExp(`${escapeRegExp(siteName)}$`), '').trim())) { title = title.replace(new RegExp(`${escapeRegExp(siteName)}$`), '').trim(); From 84f8b3a812db45ace79b7792c26a755dbd03b8dc Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 1 May 2017 16:45:34 +0900 Subject: [PATCH 2/4] [general] missing semicoron --- src/general.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/general.ts b/src/general.ts index 84f8c85..94cb41a 100644 --- a/src/general.ts +++ b/src/general.ts @@ -73,7 +73,7 @@ export default async (url: URL.Url): Promise => { const favicon = $('link[rel="shortcut icon"]').attr('href') || $('link[rel="icon"]').attr('href') || - '/favicon.ico' + '/favicon.ico'; const checkExistence = (checkURL: string): Promise => new Promise(done => { request.head(checkURL, (err, res) => { @@ -95,7 +95,7 @@ export default async (url: URL.Url): Promise => { if (isAbsolute) return relativeURLString; // スラッシュを付けて返却 return "/" + relativeURLString; - } + }; const icon = await checkExistence(URL.resolve(url.href, favicon)) || // 相対指定を絶対指定に変換し再試行 From 21717419935c762657f83eb0b04d7b836e757ee7 Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 1 May 2017 16:51:13 +0900 Subject: [PATCH 3/4] [package] remove gulp --- gulpfile.js | 19 ------------------- package.json | 8 +------- 2 files changed, 1 insertion(+), 26 deletions(-) delete mode 100644 gulpfile.js diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index dd4259a..0000000 --- a/gulpfile.js +++ /dev/null @@ -1,19 +0,0 @@ -'use strict'; - -const gulp = require('gulp'); -const ts = require('gulp-typescript'); -const es = require('event-stream'); - -const project = ts.createProject('tsconfig.json'); - -gulp.task('build', () => { - const tsResult = project - .src() - .pipe(project()); - - return es.merge( - tsResult.js - .pipe(gulp.dest('./built/')), - tsResult.dts.pipe(gulp.dest('./built/')) - ); -}); diff --git a/package.json b/package.json index 2ae737c..2e63eb1 100644 --- a/package.json +++ b/package.json @@ -9,22 +9,16 @@ "main": "./built/index.js", "types": "./built/index.d.ts", "scripts": { - "build": "gulp build", + "build": "tsc", "test": "mocha --harmony" }, "devDependencies": { "@types/debug": "0.0.29", "@types/express": "4.0.35", "@types/mocha": "2.2.40", - "@types/event-stream": "3.3.31", - "@types/gulp": "4.0.2", - "@types/gulp-typescript": "0.0.33", "@types/node": "7.0.14", "@types/request": "0.0.42", - "event-stream": "3.3.4", "express": "4.14.1", - "gulp": "3.9.1", - "gulp-typescript": "3.1.6", "mocha": "3.3.0", "typescript": "2.2.2" }, From 6933227a1a499219584f60023fa83fd598944ef8 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Mon, 1 May 2017 20:54:11 +0000 Subject: [PATCH 4/4] chore(package): update @types/node to version 7.0.15 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2e63eb1..67d02bd 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@types/debug": "0.0.29", "@types/express": "4.0.35", "@types/mocha": "2.2.40", - "@types/node": "7.0.14", + "@types/node": "7.0.15", "@types/request": "0.0.42", "express": "4.14.1", "mocha": "3.3.0",