Commit c4dea460 authored by Alice Wyan's avatar Alice Wyan

Refactor domainAndTitle into smaller pieces

parent dc00cf4c
...@@ -37,8 +37,15 @@ function documentMetadata(annotation) { ...@@ -37,8 +37,15 @@ function documentMetadata(annotation) {
* card. * card.
*/ */
function domainAndTitle(annotation) { function domainAndTitle(annotation) {
var document = documentMetadata(annotation); return {
var titleLink = document.uri; domain: domainTextFromAnnotation(annotation),
titleText: titleTextFromAnnotation(annotation),
titleLink: titleLinkFromAnnotation(annotation),
};
}
function titleLinkFromAnnotation(annotation) {
var titleLink = annotation.uri;
if (titleLink && !(titleLink.indexOf('http://') === 0 || titleLink.indexOf('https://') === 0)) { if (titleLink && !(titleLink.indexOf('http://') === 0 || titleLink.indexOf('https://') === 0)) {
// We only link to http(s) URLs. // We only link to http(s) URLs.
...@@ -49,6 +56,12 @@ function domainAndTitle(annotation) { ...@@ -49,6 +56,12 @@ function domainAndTitle(annotation) {
titleLink = annotation.links.incontext; titleLink = annotation.links.incontext;
} }
return titleLink;
}
function domainTextFromAnnotation(annotation) {
var document = documentMetadata(annotation);
var domainText = ''; var domainText = '';
if (document.uri && document.uri.indexOf('file://') === 0 && document.title) { if (document.uri && document.uri.indexOf('file://') === 0 && document.title) {
var parts = document.uri.split('/'); var parts = document.uri.split('/');
...@@ -60,16 +73,18 @@ function domainAndTitle(annotation) { ...@@ -60,16 +73,18 @@ function domainAndTitle(annotation) {
domainText = document.domain; domainText = document.domain;
} }
return domainText;
}
function titleTextFromAnnotation(annotation) {
var document = documentMetadata(annotation);
var titleText = document.title; var titleText = document.title;
if (titleText.length > 30) { if (titleText.length > 30) {
titleText = titleText.slice(0, 30) + '…'; titleText = titleText.slice(0, 30) + '…';
} }
return { return titleText;
domain: domainText,
titleText: titleText,
titleLink: titleLink,
};
} }
/** Return `true` if the given annotation is a reply, `false` otherwise. */ /** Return `true` if the given annotation is a reply, `false` otherwise. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment