mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-17 02:01:29 +10:00
🚀 release: v3.0.0
This commit is contained in:
35
apps/client/utils/getResumeUrl.ts
Normal file
35
apps/client/utils/getResumeUrl.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { Resume } from '@reactive-resume/schema';
|
||||
import get from 'lodash/get';
|
||||
|
||||
type Options = {
|
||||
withHost?: boolean;
|
||||
shortUrl?: boolean;
|
||||
buildUrl?: boolean;
|
||||
};
|
||||
|
||||
const defaultOptions: Options = {
|
||||
withHost: false,
|
||||
shortUrl: false,
|
||||
buildUrl: false,
|
||||
};
|
||||
|
||||
const getResumeUrl = (resume: Resume, options: Options = defaultOptions): string => {
|
||||
const username: string = get(resume, 'user.username');
|
||||
const shortId: string = get(resume, 'shortId');
|
||||
const slug: string = get(resume, 'slug');
|
||||
|
||||
let url = '';
|
||||
let hostname = '';
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
hostname = window.location.origin;
|
||||
}
|
||||
|
||||
url = options.withHost ? `${hostname}` : url;
|
||||
url = options.shortUrl ? `${url}/r/${shortId}` : `${url}/${username}/${slug}`;
|
||||
url = options.buildUrl ? `${url}/build` : url;
|
||||
|
||||
return url;
|
||||
};
|
||||
|
||||
export default getResumeUrl;
|
||||
Reference in New Issue
Block a user