Skip to content

Commit

Permalink
Fixes #1975: Decorate each post with a class that matches the blog ho…
Browse files Browse the repository at this point in the history
…st platform

* Removed old function to parse hostname, replaced with new extractBlogClassName
* Changed to create new URL within extractBlogClassName function instead
  • Loading branch information
rjayroso committed Apr 5, 2021
1 parent f0bc060 commit 8949d34
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/web/src/components/Posts/Post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,20 @@ const formatPublishedDate = (dateString: string) => {
}).format(date);
};

const extractBlogClassName = (url: string) => {
const blogClassName = new URL(url).hostname;
if (blogClassName.endsWith('medium.com')) {
return 'is-medium';
}
if (blogClassName.endsWith('dev.to')) {
return 'is-devto';
}
if (blogClassName.endsWith('blogspot.com')) {
return 'is-blogspot';
}
return 'is-generic';
};

const PostComponent = ({ postUrl }: Props) => {
const classes = useStyles();
const theme = useTheme();
Expand Down Expand Up @@ -284,7 +298,7 @@ const PostComponent = ({ postUrl }: Props) => {
<div className={classes.content}>
<section
ref={sectionEl}
className="telescope-post-content"
className={`telescope-post-content ${extractBlogClassName(post.url)}`}
dangerouslySetInnerHTML={{ __html: post.html }}
/>
</div>
Expand Down

0 comments on commit 8949d34

Please sign in to comment.