'use strict'const{posix:path}=require('path')module.exports=(to,from,ctx)=>{if(!to)return'#'if(to.charAt()!=='/')returnto// NOTE only legacy invocation provides both to and fromif(!ctx)from=(ctx=from).data.root.page.urlif(!from)return(ctx.data.root.site.path||'')+tolethash=''consthashIdx=to.indexOf('#')if(~hashIdx){hash=to.slice(hashIdx)to=to.slice(0,hashIdx)}if(to===from)returnhash||(isDir(to)?'./':path.basename(to))constrel=path.relative(path.dirname(from+'.'),to)returnrel?(isDir(to)?rel+'/':rel)+hash:(isDir(to)?'./':'../'+path.basename(to))+hash}functionisDir(str){returnstr.charAt(str.length-1)==='/'}