Skip to content

Commit

Permalink
fix: fix epub utils path
Browse files Browse the repository at this point in the history
  • Loading branch information
baicie committed Jan 5, 2024
1 parent 6182cbf commit 8b8e494
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/epub/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import path from 'node:path'
import fs from 'node:fs'
import { get } from 'lodash'
import mime from 'mime-types'
import type { Nav, TocNavPoint } from './types'

interface ItemWithDollar {
Expand Down Expand Up @@ -54,13 +51,30 @@ export function transformNavPoint(nav: TocNavPoint[], parentId: string = 'root')
})
}

function usePath() {
function dirname(path: string) {
return path.includes('/') ? path.split('/').slice(0, -1).join('/') : ''
}

function resolve(form: string, to: string) {
const parts = [form, to]
return parts.join('/').replace(/\/+/g, '/')
}

return {
dirname,
resolve,
}
}

/**
*
* @param importer 引用者得路径 guide
* @param id 被引用的路径 图片
* @returns
*/
export function resolveId(importer: string, id: string) {
const path = usePath()
let res = ''
const bareImportRE = /^(?![a-zA-Z]:)[\w@](?!.*:\/\/)/
if (!(importer && id))
Expand Down

0 comments on commit 8b8e494

Please sign in to comment.