Skip to content

Commit

Permalink
✌️
Browse files Browse the repository at this point in the history
  • Loading branch information
syuilo committed Sep 14, 2016
1 parent a410eba commit 8840048
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "summaly",
"version": "1.0.0",
"version": "1.1.0",
"description": "Get web page's summary",
"author": "syuilo <i@syuilo.com>",
"license": "MIT",
Expand All @@ -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"
}
}
16 changes: 6 additions & 10 deletions src/general.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -25,7 +27,6 @@ export default async (url: URL.Url): Promise<any> => {
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();
Expand All @@ -38,12 +39,7 @@ export default async (url: URL.Url): Promise<any> => {

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') ||
Expand All @@ -53,7 +49,6 @@ export default async (url: URL.Url): Promise<any> => {
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');
Expand All @@ -67,20 +62,21 @@ export default async (url: URL.Url): Promise<any> => {
}

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,
Expand Down

0 comments on commit 8840048

Please sign in to comment.