Skip to content

Commit d43e17e

Browse files
committed
chore: hashnode's blogs domain updated
1 parent c18a9ca commit d43e17e

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

src/components/Blog/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { get } from 'lodash';
55
import * as gtag from '@lib/gtag';
66
import { IS_PRODUCTION } from '@lib/constants';
77
import PropTypes from 'prop-types';
8+
import { getHashnodePubDomain } from '@utils/user-mapping';
89
import { ShowMoreButton, ButtonContainer } from './styles';
910

1011
const Blog = ({ user = {} }) => {
@@ -31,9 +32,7 @@ const Blog = ({ user = {} }) => {
3132
dateFeatured,
3233
dateAdded,
3334
} = post;
34-
const url = user?.hashnode?.publicationDomain
35-
? `http://${user?.hashnode?.publicationDomain}/${slug}`
36-
: '#';
35+
const url = getHashnodePubDomain(user, slug);
3736
return (
3837
<Post
3938
key={_id}
@@ -86,7 +85,7 @@ const Blog = ({ user = {} }) => {
8685
return `https://hashnode.com/@${get(user, 'username')}`;
8786
}
8887
if (user.hasDevto) {
89-
return `https://dev.to/${user.username}`;
88+
return `https://dev.to/${get(user, 'username')}`;
9089
}
9190
return '#';
9291
};

src/pages/api/user/[username].js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default async function handler(req, res) {
2323
case 'PUT' /* Edit a model by its ID */:
2424
try {
2525
const { body: userBody } = req;
26+
console.log(userBody);
2627
// Make sure this account doesn't already exist
2728
const userExists = await User.findOne({
2829
username,

src/services/user.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fetchAPI from '@lib/fetch-api';
2+
import { IS_GENERATOR } from '@lib/constants';
23

34
const headers = {
45
Accept: 'application/json',
@@ -11,7 +12,7 @@ export const updateUser = (username = '', input = {}) => {
1112
headers,
1213
method: 'PUT',
1314
body: JSON.stringify(input),
14-
throwOnHTTPError: true,
15+
throwOnHTTPError: IS_GENERATOR,
1516
})
1617
.then((res) => {
1718
if (res.success) {
@@ -32,7 +33,7 @@ export const upsertUser = (body) => {
3233
headers,
3334
method: 'POST',
3435
body: JSON.stringify(body),
35-
throwOnHTTPError: true,
36+
throwOnHTTPError: IS_GENERATOR,
3637
})
3738
.then((res) => {
3839
resolve(res);

src/utils/user-mapping.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,10 @@ export const getHeadData = ({ isPortfolio, user }) => {
159159
}
160160
return head;
161161
};
162+
163+
export const getHashnodePubDomain = (user, slug = '') => {
164+
if (!isEmpty(get(user, 'hashnode.publicationDomain'))) {
165+
return `http://${user?.hashnode?.publicationDomain}/${slug}`;
166+
}
167+
return `https://${get(user, 'username')}.hashnode.dev/${slug}`;
168+
};

0 commit comments

Comments
 (0)