Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBS-13804: Show review links as such on sidebar #3404

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion root/cdtoc/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export function isPerfectMatch(
medium: MediumT,
cdToc: CDTocT,
): boolean {
console.log(medium);
const mediumLengths = medium.cdtoc_track_lengths;
if (!mediumLengths) {
throw new Error('cdtoc_track_lengths were not loaded');
Expand Down
29 changes: 23 additions & 6 deletions root/layout/components/ExternalLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ component ExternalLinks(
}

const links = [];
const blogLinks = [];
const blogsAndReviews = [];
const otherLinks: Array<{
+editsPending: boolean,
+entityCredit: string,
Expand Down Expand Up @@ -108,8 +108,8 @@ component ExternalLinks(
url={target}
/>,
);
} else if (/^blog$/.test(linkType.name)) {
blogLinks.push(
} else if (linkType.name === 'blog') {
blogsAndReviews.push(
<ExternalLink
className="blog-favicon"
editsPending={relationship.editsPending}
Expand All @@ -119,6 +119,23 @@ component ExternalLinks(
url={target}
/>,
);
} else if (linkType.name === 'review') {
const urlObject = new URL(target.name);
const hostName = urlObject.host.replace('www.', '');

blogsAndReviews.push(
<ExternalLink
className="review-favicon"
editsPending={relationship.editsPending}
entityCredit={entityCredit}
key={relationship.id}
text={texp.l(
'Review ({hostname})',
{hostname: hostName},
)}
url={target}
/>,
);
} else if (target.show_in_external_links /*:: === true */) {
otherLinks.push({
editsPending: relationship.editsPending,
Expand All @@ -129,7 +146,7 @@ component ExternalLinks(
}
}

if (!(links.length || blogLinks.length || otherLinks.length)) {
if (!(links.length || blogsAndReviews.length || otherLinks.length)) {
return null;
}

Expand All @@ -142,8 +159,8 @@ component ExternalLinks(
compare(a.url.href_url, b.url.href_url)
));

// We ensure official sites are listed above blogs, and blogs above others
links.push(...blogLinks);
// We list official sites above blogs/reviews, and those above others
links.push(...blogsAndReviews);
links.push(...uniqueOtherLinks.map(({id, ...props}) => (
<ExternalLink key={id} {...props} />
)));
Expand Down
7 changes: 4 additions & 3 deletions root/static/images/attribution.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ Images:
Image set: Gentleface Mono Icon Set
Author: Gentleface.com
License: CC-NC-ND-BY/3.0 (see: http://creativecommons.org/licenses/by-nc-nd/3.0/)
Download: http://gentleface.com/free_icon_set.html
Download: https://www.iconfinder.com/iconsets/cc_mono_icon_set
Images:

external-favicons/home-32.png (original: black/png/home_icon&32.png)
external-favicons/blog-32.png (original: black/png/speechbubble_sq_line_icon&32.png)
external-favicons/home-32.png (original: https://www.iconfinder.com/icons/42257/about_icon)
external-favicons/blog-32.png (original: https://www.iconfinder.com/icons/42282/notepad_icon)
external-favicons/review-32.png (original: https://www.iconfinder.com/icons/42347/line_spechbubble_sq_icon)

----------------------------------------------------------------------------

Expand Down
Binary file modified root/static/images/external-favicons/blog-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added root/static/images/external-favicons/review-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 39 additions & 36 deletions root/static/scripts/edit/externalLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,42 @@ type LinksEditorState = {
+links: $ReadOnlyArray<LinkStateT>,
};

function getFaviconClass(
relationships: $ReadOnlyArray<LinkRelationshipT>,
url: string,
) {
let faviconClass = '';

for (const relationship of relationships) {
const linkType = relationship.type
? linkedEntities.link_type[relationship.type]
: null;

if (linkType) {
// If we find a homepage, that's the icon we want and we're done
if (/^official (?:homepage|site)$/.test(linkType.name)) {
return 'home';
} else if (linkType.name === 'blog') {
faviconClass = 'blog';
} else if (linkType.name === 'review') {
faviconClass = 'review';
}
}
}

if (nonEmpty(faviconClass)) {
return faviconClass;
}

for (const key of Object.keys(FAVICON_CLASSES)) {
if (url.indexOf(key) > 0) {
return FAVICON_CLASSES[key];
}
}

return 'no';
}

export class _ExternalLinksEditor
extends React.Component<LinksEditorProps, LinksEditorState> {
creditableEntityProp: 'entity0_credit' | 'entity1_credit' | null;
Expand Down Expand Up @@ -1428,42 +1464,9 @@ export class ExternalLink extends React.Component<LinkProps> {
});
const firstLink = props.relationships[0];

let faviconClass: string | void;
for (const key of Object.keys(FAVICON_CLASSES)) {
if (props.url.indexOf(key) > 0) {
faviconClass = FAVICON_CLASSES[key];
break;
}
}
if (notEmpty && !faviconClass) {
const isHomepage = props.relationships.some(link => {
const linkType = link.type
? linkedEntities.link_type[link.type]
: null;
if (linkType) {
return /^official (?:homepage|site)$/.test(linkType.name);
}
return false;
});
if (isHomepage) {
faviconClass = 'home';
} else {
const isBlog = props.relationships.some(link => {
const linkType = link.type
? linkedEntities.link_type[link.type]
: null;
if (linkType) {
return /^blog$/.test(linkType.name);
}
return false;
});
if (isBlog) {
faviconClass = 'blog';
} else {
faviconClass = 'no';
}
}
}
const faviconClass = notEmpty
? getFaviconClass(props.relationships, props.url)
: null;

return (
<>
Expand Down
1 change: 1 addition & 0 deletions root/static/styles/favicons.less
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

.favicon("home", 32);
.favicon("blog", 32);
.favicon("review", 32);

.favicon("allmusic");
.favicon("amazon", 32);
Expand Down