-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 99068fa
Showing
21 changed files
with
456 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
version: 2.1 | ||
|
||
orbs: | ||
codecov: codecov/[email protected] | ||
|
||
executors: | ||
go-114: | ||
docker: | ||
# https://hub.docker.com/layers/circleci/golang/1.14-node/images/sha256-2190fa9a5f81e3cb4397147d11aeaa88c22e6e35d401eead90195925230e071d?context=explore | ||
- image: circleci/golang:1.14-node | ||
working_directory: /go/src/github.com/kemokemo/furit | ||
|
||
jobs: | ||
test: | ||
executor: go-114 | ||
steps: | ||
- checkout | ||
- run: go version | ||
- run: go get -v -t -d ./... | ||
- run: go test -v -cover -coverprofile=coverage.out ./... | ||
- codecov/upload: | ||
file: ./coverage.out | ||
lint: | ||
executor: go-114 | ||
steps: | ||
- checkout | ||
- run: go get -v -t -d ./... | ||
# see here: https://github.com/golang/lint/issues/415#issuecomment-511234597 | ||
- run: go get -u golang.org/x/lint/golint | ||
- run: golint ./... | ||
- run: go vet ./... | ||
build: | ||
executor: go-114 | ||
steps: | ||
- checkout | ||
- run: go get -v -t -d ./... | ||
- run: go build | ||
deploy: | ||
executor: go-114 | ||
steps: | ||
- run: echo 'export PATH=${GOPATH}/bin/:${PATH}' >> $BASH_ENV | ||
- checkout | ||
- run: go get -v -t -d ./... | ||
- run: go get github.com/mitchellh/gox | ||
- run: go get github.com/tcnksm/ghr | ||
- run: mkdir release | ||
- run: gox -output "./release/{{.Dir}}_{{.OS}}_{{.Arch}}" ./ ./... | ||
- run: ghr -u $CIRCLE_PROJECT_USERNAME $CIRCLE_TAG release/ | ||
|
||
workflows: | ||
version: 2 | ||
test, lint and build: | ||
jobs: | ||
- test | ||
- lint | ||
- build: | ||
requires: | ||
- lint | ||
deploy: | ||
jobs: | ||
- build: | ||
filters: | ||
tags: | ||
only: /.*/ | ||
- deploy: | ||
requires: | ||
- build | ||
filters: | ||
tags: | ||
only: /^v.*/ | ||
branches: | ||
ignore: /.*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
furit | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# OS files | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 kemokemo | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# furit ( <u>F</u>ind <u>U</u>n<u>r</u>eferenced <u>I</u>mages in <u>T</u>ext files ) | ||
|
||
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) [![CircleCI](https://circleci.com/gh/kemokemo/furit.svg?style=svg)](https://circleci.com/gh/kemokemo/furit) [![codecov](https://codecov.io/gh/kemokemo/furit/branch/master/graph/badge.svg)](https://codecov.io/gh/kemokemo/furit) [![Go Report Card](https://goreportcard.com/badge/github.com/kemokemo/furit)](https://goreportcard.com/report/github.com/kemokemo/furit) | ||
|
||
This tool finds unreferenced image assets from text files such as markdown. | ||
|
||
## Install | ||
|
||
### Binary | ||
|
||
Get the latest version from [the release page](https://github.com/kemokemo/furit/releases/latest), and download the archive file for your operating system/architecture. Unpack the archive, and put the binary somewhere in your `$PATH`. | ||
|
||
## Usage | ||
|
||
```sh | ||
$ furit -h | ||
Usage: furit [<option>...] <1st path> <2nd path>... | ||
you can set mutiple paths to search invalid images. | ||
|
||
-h display help | ||
``` | ||
|
||
Currently, only Markdown format is supported as text to find links to images. | ||
|
||
### Example | ||
|
||
``` | ||
$ furit lib/test-data/markdown | ||
lib/test-data/markdown/assets/画面.bmp | ||
lib/test-data/markdown/テスト.gif | ||
``` | ||
|
||
This tool looks recursively for the folder you specify, finds links to images in the text it finds, and enumerates the unlinked image files from text. | ||
|
||
## License | ||
|
||
[MIT](https://github.com/kemokemo/furit/blob/master/LICENSE) | ||
|
||
## Author | ||
|
||
[kemokemo](https://github.com/kemokemo) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package furit | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
type imageFinder struct{} | ||
|
||
const imgFileFormat = `\.(png|PNG|jpg|JPG|jpeg|JPEG|bmp|BMP|gif|GIF|tiff|TIFF)` | ||
|
||
var imgFileReg = regexp.MustCompile(imgFileFormat) | ||
|
||
// Find finds image files and returns paths to the program. | ||
func (i *imageFinder) Find(root string) ([]string, error) { | ||
var imgPaths []string | ||
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { | ||
if err != nil || info == nil { | ||
return fmt.Errorf("failed to walk for image: %v", err) | ||
} | ||
// Exclude directories with names beginning with a dot. ex) .git, .node_modules etc.. | ||
if info.IsDir() && strings.HasPrefix(info.Name(), ".") { | ||
return filepath.SkipDir | ||
} | ||
|
||
if info.IsDir() || !imgFileReg.MatchString(info.Name()) { | ||
return nil | ||
} | ||
imgPaths = append(imgPaths, path) | ||
return nil | ||
}) | ||
|
||
return imgPaths, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package furit | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func Test_imageFinder_Find(t *testing.T) { | ||
type args struct { | ||
root string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want []string | ||
wantErr bool | ||
}{ | ||
{name: "test-data", args: args{root: "./test-data/image-files"}, | ||
want: []string{ | ||
"test-data/image-files/blank.jpg", | ||
"test-data/image-files/sample.png", | ||
"test-data/image-files/画像/テスト.gif", | ||
"test-data/image-files/画面.bmp", | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
i := &imageFinder{} | ||
got, err := i.Find(tt.args.root) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("imageFinder.Find() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("imageFinder.Find() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package furit | ||
|
||
// ImageFinder finds image files | ||
type ImageFinder interface { | ||
// Find finds image files and returns paths to the program. | ||
Find(root string) ([]string, error) | ||
} | ||
|
||
// Image is the finder of image files. | ||
var Image ImageFinder = (*imageFinder)(nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package furit | ||
|
||
// ImageLinkFinder will search files and find image links. | ||
type ImageLinkFinder interface { | ||
// Find converts the path of images referenced by text to paths relative to the program and returns it. | ||
Find(root string) ([]string, error) | ||
} | ||
|
||
// Markdown is the finder of image link from markdown file. | ||
var Markdown ImageLinkFinder = (*markdown)(nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package furit | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
type markdown struct{} | ||
|
||
const mdImgLinkFormat = `\!\[.*\]\((.+\.(png|PNG|jpg|JPG|jpeg|JPEG|bmp|BMP|gif|GIF|tiff|TIFF))\)` | ||
|
||
var mdLinkReg = regexp.MustCompile(mdImgLinkFormat) | ||
|
||
// Find converts the path of images referenced by text to paths relative to the program and returns it. | ||
func (m *markdown) Find(root string) ([]string, error) { | ||
var links []string | ||
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { | ||
if err != nil || info == nil { | ||
return fmt.Errorf("failed to walk for markdown: %v", err) | ||
} | ||
// Exclude directories with names beginning with a dot. ex) .git, .node_modules etc.. | ||
if info.IsDir() && strings.HasPrefix(info.Name(), ".") { | ||
return filepath.SkipDir | ||
} | ||
|
||
ext := filepath.Ext(info.Name()) | ||
if info.IsDir() || (ext != ".md" && ext != ".markdown") { | ||
return nil | ||
} | ||
|
||
f, err := os.Open(path) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
|
||
s := bufio.NewScanner(f) | ||
for s.Scan() { | ||
group := mdLinkReg.FindSubmatch([]byte(s.Text())) | ||
if len(group) > 1 { | ||
links = append(links, filepath.Join(filepath.Dir(path), string(group[1]))) | ||
} | ||
} | ||
return nil | ||
}) | ||
|
||
return links, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package furit | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func Test_markdown_Find(t *testing.T) { | ||
type args struct { | ||
root string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want []string | ||
wantErr bool | ||
}{ | ||
{name: "test-data", args: args{root: "test-data/markdown"}, | ||
want: []string{ | ||
"test-data/markdown/posts/assets/gopher.png", | ||
"test-data/markdown/assets/sample1.png", | ||
"test-data/markdown/assets/サンプル.png", | ||
"test-data/markdown/logo.jpg", | ||
"test-data/markdown/テスト.png", | ||
}, wantErr: false}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
m := &markdown{} | ||
got, err := m.Find(tt.args.root) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("markdown.Find() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("markdown.Find() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# my first post | ||
|
||
## Hey! | ||
|
||
![gopher](assets/gopher.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# test markdown | ||
|
||
## Chapter 1 | ||
|
||
![sample](assets/sample1.png) | ||
|
||
![サンプル](assets/サンプル.png) | ||
|
||
## Chapter 2 | ||
|
||
![logo](logo.jpg) | ||
|
||
![](テスト.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.