Skip to content

Commit

Permalink
enhance comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Oct 30, 2023
1 parent 4529e53 commit e4a4015
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (b *broker) LocalPath(e *entry) string {
if entryPath == "" {
return ""
}
if isGivenPath(entryPath) {
if isLikelyGivenPath(entryPath) {
// EditURL is like bellow
// https://blog.hatena.ne.jp/Songmu/songmu.hatenadiary.org/atom/entry/6801883189050452361
paths := strings.Split(e.EditURL, "/")
Expand Down Expand Up @@ -134,7 +134,7 @@ func (b *broker) Store(e *entry, path, origPath string) error {
if entryPath == "" {
return fmt.Errorf("invalid path: %s", e.URL.Path)
}
if isGivenPath(entryPath) {
if isLikelyGivenPath(entryPath) {
e.URL = nil
}
}
Expand Down
17 changes: 10 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,19 @@ var commandFetch = &cli.Command{
}

var (
// 標準フォーマット: 2011/11/07/161845
defaultBlogPathReg = regexp.MustCompile(`^2[01][0-9]{2}/[01][0-9]/[0-3][0-9]/[0-9]{6}$`)
// はてなダイアリー風フォーマット: 20111107/1320650325
hatenaDiaryPathReg = regexp.MustCompile(`^2[01][0-9]{2}[01][0-9][0-3][0-9]/[0-9]{9,12}$`)
titlePathReg = regexp.MustCompile(`^2[01][0-9]{2}/[01][0-9]/[0-3][0-9]/.+$`)
draftDir = "_draft/"
// タイトルフォーマット: 2011/11/07/週末は川に行きました
titlePathReg = regexp.MustCompile(`^2[01][0-9]{2}/[01][0-9]/[0-3][0-9]/.+$`)
draftDir = "_draft/"
)

func isGivenPath(path string) bool {
return defaultBlogPathReg.MatchString(path) ||
hatenaDiaryPathReg.MatchString(path) ||
titlePathReg.MatchString(path)
func isLikelyGivenPath(p string) bool {
return defaultBlogPathReg.MatchString(p) ||
hatenaDiaryPathReg.MatchString(p) ||
titlePathReg.MatchString(p)
}

var commandPush = &cli.Command{
Expand Down Expand Up @@ -269,7 +272,7 @@ var commandPush = &cli.Command{
blogPath = "/" + filepath.ToSlash(blogPath)

if _, entryPath := extractEntryPath(path); entryPath != "" {
if !isGivenPath(entryPath) && !strings.HasPrefix(entryPath, draftDir) {
if !isLikelyGivenPath(entryPath) && !strings.HasPrefix(entryPath, draftDir) {
entry.CustomPath = entryPath
}
}
Expand Down

0 comments on commit e4a4015

Please sign in to comment.