import { toId } from '@proof-ui/utils' ; import URL from 'url-parse' ; import urlJoin from 'url-join' ; export function normalizeBaseURL ( url ) { let normalized = url ; if ( ! normalized . startsWith ( 'http' ) ) { normalized = urlJoin ( 'http:' , normalized ) ; } const parsed = new URL ( normalized ) ; let path = '' ; if ( parsed . pathname ) { path = parsed . pathname ; if ( parsed . pathname . endsWith ( '.html' ) ) { const splitPathname = path . split ( '/' ) ; path = splitPathname . slice ( 0 , - 1 ) . join ( '/' ) ; } } return urlJoin ( parsed . protocol , parsed . host , path ) ; } export function getStoryURL ( base , kind ? , story ? ) { if ( ! kind || ! story ) { return base ; } return urlJoin ( base , 'iframe.html' , `?id=${ toId ( kind , story ) }` ) ; }