Skip to content

Commit

Permalink
skip gm executable when moving files
Browse files Browse the repository at this point in the history
  • Loading branch information
kpym committed Jan 25, 2024
1 parent 5eca1b1 commit 5ce8d14
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion HOWTO.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Here is an example of possible `.gitlab-ci.yml`:
pages:
image: alpine
script:
- wget -c https://github.com/kpym/gm/releases/download/v0.16.0/gm_0.16.0_Linux_64bit.tar.gz -O - | tar -xz gm
- wget -c https://github.com/kpym/gm/releases/download/v0.16.1/gm_0.16.1_Linux_64bit.tar.gz -O - | tar -xz gm
- ./gm --pages '**/*'
artifacts:
paths:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This tool is a thin wrapper around the [github.com/yuin/goldmark](https://github

```
> gm -h
gm (version: 0.16.0): a goldmark cli tool which is a thin wrapper around github.com/yuin/goldmark (versio: v1.5.6).
gm (version: 0.16.1): a goldmark cli tool which is a thin wrapper around github.com/yuin/goldmark (versio: v1.5.6).
If not serving (no '--serve' or '-s' option is used):
- the .md files are converted and saved as .html with the same base name;
Expand Down
23 changes: 21 additions & 2 deletions gm_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ func buildMd(infile string) {
}
}

var thisExecutable string

func setThisExecutable(cwd string) {
var err error
thisExecutable, err = filepath.Rel(cwd, filepath.Clean(os.Args[0]))
check(err, "Problem getting the current executable.")
}

// isGM returns true if the path is equal to the current executable
// path is should be cleaned before calling this function
func isGM(path string) bool {
return path == thisExecutable
}

// pathHasDot returns true if the path contains a folder or file name starting with a dot
func pathHasDot(path string) bool {
wasSeparator := true
for i := 0; i < len(path); i++ {
Expand All @@ -72,11 +87,15 @@ func pathHasDot(path string) bool {

// buildFiles convert all .md files verifying one of the patterns to .html
func buildFiles() {
// get the current directory as a filesystem, needed for doublestar.Glob
// get the current directory as a filesystem
cwd, err := os.Getwd()
check(err, "Problem getting the current directory.")
// set fs needed for doublestar.Glob
dirFS := os.DirFS(cwd)
// check if we need to move files
movefiles := move && filepath.Clean(outdir) != filepath.Clean(cwd)
// set the current executable (to skip if necessary)
setThisExecutable(cwd)
// check all patterns
for _, pattern := range inpatterns {
info("Looking for '%s'.\n", pattern)
Expand All @@ -95,7 +114,7 @@ func buildFiles() {
}
for _, infile := range allfiles {
infile = filepath.Clean(infile)
if skipdot && pathHasDot(infile) {
if isGM(infile) || skipdot && pathHasDot(infile) {
info(" Skipping %s...\n", infile)
continue
}
Expand Down

0 comments on commit 5ce8d14

Please sign in to comment.