mirror of
https://github.com/misskey-dev/summaly.git
synced 2025-05-24 15:07:23 +09:00
Merge branch 'master' into greenkeeper/@types/mocha-2.2.41
This commit is contained in:
commit
4c3ecf999d
19
gulpfile.js
19
gulpfile.js
@ -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/'))
|
||||
);
|
||||
});
|
10
package.json
10
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.41",
|
||||
"@types/event-stream": "3.3.31",
|
||||
"@types/gulp": "4.0.2",
|
||||
"@types/gulp-typescript": "0.0.33",
|
||||
"@types/node": "7.0.14",
|
||||
"@types/node": "7.0.15",
|
||||
"@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"
|
||||
},
|
||||
|
@ -70,31 +70,37 @@ export default async (url: URL.Url): Promise<Summary> => {
|
||||
|
||||
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) => {
|
||||
const checkExistence = (checkURL: string): Promise<string> => new Promise(done => {
|
||||
request.head(checkURL, (err, res) => {
|
||||
if (err) {
|
||||
done(false);
|
||||
done(null);
|
||||
} else if (res.statusCode == 200) {
|
||||
done(true);
|
||||
done(checkURL);
|
||||
} else {
|
||||
done(false);
|
||||
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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user