view util.go @ 5:af840bc25791

impl edit cmd
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Fri, 04 Dec 2020 18:27:09 +0900
parents 76695bcbe426
children 0dc44ee170b4
line wrap: on
line source

package growsync

import (
	"os"
	"path/filepath"
	"strings"
)

func convertGrowiSystemPath(inputPath string) string {
	/*
		iputPath: Gears -> /Gears
		inputPath: Gears/CbC/hoge.md -> /Gears/CbC/hoge
	*/

	outputPATH := inputPath

	if index := strings.Index(inputPath, "/"); index != 0 {
		outputPATH = "/" + inputPath
	}

	if strings.HasSuffix(outputPATH, ".md") {
		outputPATH = strings.TrimSuffix(outputPATH, filepath.Ext(outputPATH))
	}

	return outputPATH
}

func existsFile(conf string) bool {
	info, err := os.Stat(conf)
	if os.IsNotExist(err) {
		return false
	}
	return !info.IsDir()
}