@/utils#expandHomeDir TypeScript Examples

The following examples show how to use @/utils#expandHomeDir. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: hexo-service.ts    From hexon with GNU General Public License v3.0 6 votes vote down vote up
//#endregion

  //#region IHexoCli
  async publish(filename: string, layout?: string) {
    const args: string[] = ["publish"]
    if (layout) args.push(layout)
    args.push(filename)
    const info = await this._hexoInstanceService.runBetweenReload(
      async () =>
        await run("hexo", args, {
          cwd: await this._hexoInstanceService.getBaseDir(),
          stripAnsi: true,
        })
    )
    const fullSource = expandHomeDir(info.split("Published: ")[1].trim())
    const article = (await this.getPostByFullSource(fullSource))!
    const res = await this.WithCategoriesTagsBriefArticleList(article)
    this._logService.log(`publish ${filename} with layout: ${layout}`)
    return res
  }
Example #2
Source File: hexo-service.ts    From hexon with GNU General Public License v3.0 6 votes vote down vote up
async create(title: string, options: ICreateOptions = {}) {
    const args: string[] = ["new"]
    if (options.layout) args.push(options.layout)
    if (options.path) {
      const base = await this._hexoInstanceService.getBaseDir()
      const fullPath = path.resolve(base, options.path)
      const relative = path.relative(fullPath, base)
      if (!relative.startsWith("..")) {
        this._logService.error(`${fullPath} is not valid`)
        throw new InvalidOptionsError(
          `${options.path} is not inside hexo blog folder`,
          "InvalidCreatePathError"
        )
      }
      args.push("--path")
      args.push(options.path)
    }
    if (options.replace) args.push("--replace")
    if (options.slug) {
      args.push("--slug")
      args.push(options.slug)
    }
    if (title) args.push(title)
    const info = await this._hexoInstanceService.runBetweenReload(async () => {
      return await run("hexo", args, {
        cwd: await this._hexoInstanceService.getBaseDir(),
        stripAnsi: true,
      })
    })
    const fullSource = expandHomeDir(info.split("Created: ")[1].trim())
    const article = (await this.getPostOrPageByFullSource(fullSource))!
    const res = this.WithCategoriesTagsBriefArticleList(article)
    this._logService.log("create succeed", fullSource)
    return res
  }