diff --git a/package.json b/package.json index 27371543..77b9ded1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "summaly", - "version": "1.0.0", + "version": "1.1.0", "description": "Get web page's summary", "author": "syuilo ", "license": "MIT", @@ -25,6 +25,7 @@ "babel-core": "6.13.2", "babel-polyfill": "6.13.0", "cheerio-httpcli": "^0.6.9", + "escape-regexp": "0.0.1", "request": "^2.74.0" } } diff --git a/src/general.ts b/src/general.ts index e4808c79..db34d7f0 100644 --- a/src/general.ts +++ b/src/general.ts @@ -1,6 +1,8 @@ import * as URL from 'url'; import * as request from 'request'; +const escapeRegExp = require('escape-regexp'); + const Entities = require('html-entities').AllHtmlEntities; const entities = new Entities(); @@ -25,7 +27,6 @@ export default async (url: URL.Url): Promise => { const $: any = res.$; let title = - $('meta[property="misskey:title"]').attr('content') || $('meta[property="og:title"]').attr('content') || $('meta[property="twitter:title"]').attr('content') || $('title').text(); @@ -38,12 +39,7 @@ export default async (url: URL.Url): Promise => { const lang: string = $('html').attr('lang'); - const type = - $('meta[property="misskey:type"]').attr('content') || - $('meta[property="og:type"]').attr('content'); - let image = - $('meta[property="misskey:image"]').attr('content') || $('meta[property="og:image"]').attr('content') || $('meta[property="twitter:image"]').attr('content') || $('link[rel="image_src"]').attr('href') || @@ -53,7 +49,6 @@ export default async (url: URL.Url): Promise => { image = image ? URL.resolve(url.href, image) : null; let description = - $('meta[property="misskey:summary"]').attr('content') || $('meta[property="og:description"]').attr('content') || $('meta[property="twitter:description"]').attr('content') || $('meta[name="description"]').attr('content'); @@ -67,20 +62,21 @@ export default async (url: URL.Url): Promise => { } let siteName = - $('meta[property="misskey:site-name"]').attr('content') || $('meta[property="og:site_name"]').attr('content') || - $('meta[name="application-name"]').attr('content'); + $('meta[name="application-name"]').attr('content') || + url.hostname; siteName = siteName ? entities.decode(siteName) : null; let icon = - $('meta[property="misskey:site-icon"]').attr('content') || $('link[rel="shortcut icon"]').attr('href') || $('link[rel="icon"]').attr('href') || '/favicon.ico'; icon = icon ? URL.resolve(url.href, icon) : null; + title = title.replace(new RegExp(`[\-\|:]?${escapeRegExp(siteName)}$`)); + return { title: title, icon: icon,