Skip to content

Commit 67d4583

Browse files
authored
remove config.yaml (#10)
1 parent 4579f0e commit 67d4583

8 files changed

Lines changed: 222 additions & 104 deletions

File tree

README.ja.md

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,24 @@ cd note-cli-demo
8585
8686
Create directory. a6b420c6-9bb2-4060-869c-20c171fc9827
8787
Create file. a6b420c6-9bb2-4060-869c-20c171fc9827.md
88-
Create file. config.yaml
8988
```
9089

9190
```
9291
.
9392
└── a6b420c6-9bb2-4060-869c-20c171fc9827
94-
├── config.yaml
9593
└── a6b420c6-9bb2-4060-869c-20c171fc9827.md
9694
```
9795

9896
- ```a6b420c6-9bb2-4060-869c-20c171fc9827.md``` 記事ファイル。ファイル名はディレクトリ名と同じで今回はランダム値(UUID)を使用しています。
99-
- ```config.yaml``` 設定ファイル。記事のタイトルや著者名などを設定するファイルです。
97+
- ~~```config.yaml``` 設定ファイル。記事のタイトルや著者名などを設定するファイルです。~~
10098

10199
```yaml:config.yaml
102100
title: article title
103101
author: your name
104102
```
105103

104+
**config.yamlは廃止しました。記事タイトルや著者名などの設定情報は記事markdownファイルのメタデータとして記載するように変更されています。**
105+
106106
3. 記事画像を生成する。
107107

108108
以下のコマンドを実行することで```output.png```が生成されます。
@@ -136,9 +136,9 @@ Complete generate OGP image
136136
```create article```コマンドを実行するとユニークなランダム値(UUID)を使用してディレクトリを作成します。ディレクトリ内には以下のファイルも併せて作成され配置されます。
137137

138138
- ```<directory name>.md``` 記事ファイル。投稿したい記事の内容をこのファイル内に書き込んでいきます。
139-
- ```config.yaml``` 記事や画像ファイルの生成に関する設定をこのファイルで行います。
139+
- ~~```config.yaml``` 記事や画像ファイルの生成に関する設定をこのファイルで行います。~~
140140

141-
### config.yaml
141+
### ~~config.yaml~~
142142

143143
```yaml
144144
title: article title
@@ -150,6 +150,26 @@ author: your name
150150
|title|string|生成する画像に載せる記事タイトル|
151151
|author|string|記事執筆者|
152152
153+
### \<directory name>.md
154+
155+
マークダウンファイルは以下のようなメタデータを持ちます。画像の出力には```title```と```author```の項目が使用されます。
156+
157+
```yaml:article.md
158+
---
159+
title: ""
160+
tags: []
161+
date: "2023-09-29"
162+
author: ""
163+
---
164+
```
165+
166+
| Field | Type | Description |
167+
| --- | --- | --- |
168+
|title|string|生成する画像に載せる記事タイトル|
169+
|tags|[]string|記事に紐づけるタグ|
170+
|date|string|ファイル作成日|
171+
|author|string|記事執筆者|
172+
153173
### ```--time(-t)```
154174

155175
このフラグを付けることでデフォルトのUUIDではなく、現在時刻でディレクトリおよびファイルを作成することができます。現在時刻はコマンド実行のOSのタイムゾーンに依存し、```YYYY-mm-dd```のフォーマットで生成されます。
@@ -158,7 +178,6 @@ author: your name
158178
% note-cli create article -t
159179
Create directory. 2023-09-08
160180
Create file. 2023-09-08.md
161-
Create file. config.yaml
162181
```
163182
164183
既にディレクトリが存在している場合、```YYYY-mm-dd-{number}```という形式でnumberをインクリメントしてディレクトリを作成します。
@@ -167,7 +186,6 @@ Create file. config.yaml
167186
% note-cli create article -t
168187
Create directory. 2023-09-08-2
169188
Create file. 2023-09-08-2.md
170-
Create file. config.yaml
171189
```
172190
173191
### ```--name(-n)```
@@ -178,12 +196,31 @@ Create file. config.yaml
178196
% note-cli create article -n article-A
179197
Create directory. article-A
180198
Create file. article-A.md
181-
Create file. config.yaml
199+
```
200+
201+
### ```--author(-a)```
202+
203+
このフラグを付けることで記事著者名を事前に渡すことができます。
204+
205+
```
206+
% go run main.go create article -a Yamanaka.J
207+
Create directory. cc4ab85a-2aa7-48a6-8472-3b36ef4778fa
208+
Create file. cc4ab85a-2aa7-48a6-8472-3b36ef4778fa/cc4ab85a-2aa7-48a6-8472-3b36ef4778fa.md
209+
210+
% cat cc4ab85a-2aa7-48a6-8472-3b36ef4778fa/cc4ab85a-2aa7-48a6-8472-3b36ef4778fa.md
211+
---
212+
title: ""
213+
tags: []
214+
date: "2023-09-29"
215+
author: "Yamanaka.J"
216+
---
182217
```
183218
184219
## create image
185220
186-
```create image```コマンドを実行することで[OGP](https://ogp.me/)画像風の画像を生成することができます。画像の生成にはカレントディレクトリに<a href="#configyaml">config.yaml</a>が存在している必要があります。もし、config.yamlが存在していなかった場合はコマンドが失敗します。
221+
```create image```コマンドを実行することで[OGP](https://ogp.me/)画像風の画像を生成することができます。~~画像の生成にはカレントディレクトリに<a href="#configyaml">config.yaml</a>が存在している必要があります。もし、config.yamlが存在していなかった場合はコマンドが失敗します。~~
222+
223+
**config.yamlは廃止となっています。代わりに、markdownファイルのメタデータが存在している必要があります。メタデータを読み取ることができなかった場合、互換性を保つためにconfig.yamlを探し、それでもなければコマンドは失敗します。**
187224
188225
```
189226
% note-cli create image

README.md

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,24 @@ cd note-cli-demo
8585
8686
Create directory. a6b420c6-9bb2-4060-869c-20c171fc9827
8787
Create file. a6b420c6-9bb2-4060-869c-20c171fc9827.md
88-
Create file. config.yaml
8988
```
9089

9190
```
9291
.
9392
└── a6b420c6-9bb2-4060-869c-20c171fc9827
94-
├── config.yaml
9593
└── a6b420c6-9bb2-4060-869c-20c171fc9827.md
9694
```
9795

9896
- ```a6b420c6-9bb2-4060-869c-20c171fc9827.md``` Article file. The file name is the same as the directory name, this time using a random value (UUID).
99-
- ```config.yaml``` Config file. This file is used to set the title of the article, the name of the author, etc.
97+
- ~~```config.yaml``` Config file. This file is used to set the title of the article, the name of the author, etc.~~
10098

10199
```yaml:config.yaml
102100
title: article title
103101
author: your name
104102
```
105103

104+
**config.yaml is obsolete. Configuration information such as article title and author name has been changed to be included as metadata in the article markdown file.**
105+
106106
3. Create article image.
107107

108108
The following command will generate ``output.png``.
@@ -136,9 +136,9 @@ Icons can also be placed on the image by providing an icon image. You can also c
136136
```create article``` command creates a directory with a unique random value (UUID). The following files will also be created and placed in the directory.
137137

138138
- ```<directory name>.md``` Article file.The content of the article you wish to submit will be written in this file.
139-
- ```config.yaml``` This file contains settings related to the generation of articles and image files.
139+
- ~~```config.yaml``` This file contains settings related to the generation of articles and image files.~~
140140

141-
### config.yaml
141+
### ~~config.yaml~~
142142

143143
```yaml
144144
title: article title
@@ -150,6 +150,26 @@ author: your name
150150
|title|string|Article Title|
151151
|author|string|Article Author|
152152
153+
### \<directory name>.md
154+
155+
The markdown file will have the following metadata The ``title`` and ``author`` fields are used for image output.
156+
157+
```yaml:article.md
158+
---
159+
title: ""
160+
tags: []
161+
date: "2023-09-29"
162+
author: ""
163+
---
164+
```
165+
166+
| Field | Type | Description |
167+
| --- | --- | --- |
168+
|title|string|Article Title|
169+
|tags|[]string|tags|
170+
|date|string|File created day|
171+
|author|string|Article Author|
172+
153173
### ```--time(-t)```
154174

155175
This flag allows directories and files to be created with the current time instead of the default UUID. The current time depends on the time zone of the operating system under which the command is executed and is generated in the format ``YYYY-mm-dd``.
@@ -158,7 +178,6 @@ This flag allows directories and files to be created with the current time inste
158178
% note-cli create article -t
159179
Create directory. 2023-09-08
160180
Create file. 2023-09-08.md
161-
Create file. config.yaml
162181
```
163182

164183
If the directory already exists, it creates the directory by incrementing number in the form ``YYYY-mm-dd-{number}``.
@@ -167,7 +186,6 @@ If the directory already exists, it creates the directory by incrementing number
167186
% note-cli create article -t
168187
Create directory. 2023-09-08-2
169188
Create file. 2023-09-08-2.md
170-
Create file. config.yaml
171189
```
172190

173191
### ```--name(-n)```
@@ -178,12 +196,31 @@ This flag allows you to create a directory with an arbitrary name. **If the dire
178196
% note-cli create article -n article-A
179197
Create directory. article-A
180198
Create file. article-A.md
181-
Create file. config.yaml
199+
```
200+
201+
### ```--author(-a)```
202+
203+
This flag allows the name of the article author to be passed in advance.
204+
205+
```
206+
% go run main.go create article -a Yamanaka.J
207+
Create directory. cc4ab85a-2aa7-48a6-8472-3b36ef4778fa
208+
Create file. cc4ab85a-2aa7-48a6-8472-3b36ef4778fa/cc4ab85a-2aa7-48a6-8472-3b36ef4778fa.md
209+
210+
% cat cc4ab85a-2aa7-48a6-8472-3b36ef4778fa/cc4ab85a-2aa7-48a6-8472-3b36ef4778fa.md
211+
---
212+
title: ""
213+
tags: []
214+
date: "2023-09-29"
215+
author: "Yamanaka.J"
216+
---
182217
```
183218

184219
## create image
185220

186-
Image like [OGP](https://ogp.me/) can be generated by executing the ```create image``` command.The <a href="#configyaml">config.yaml</a> must exist in the current directory to generate images.If config.yaml does not exist, the command will fail.
221+
Image like [OGP](https://ogp.me/) can be generated by executing the ```create image``` command.~~The <a href="#configyaml">config.yaml</a> must exist in the current directory to generate images.If config.yaml does not exist, the command will fail.~~
222+
223+
**config.yaml is obsolete. Instead, the metadata for the markdown file must be present. If the metadata cannot be read, config.yaml is searched for compatibility, and if it is still missing, the command will fail.**
187224

188225
```
189226
% note-cli create image

cmd/article.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ You can also specify the -t(--time) option to make the current timestamp the fil
1515
If nothing is specified, the file is created with a unique file name by UUID.
1616
`,
1717
Args: cobra.NoArgs,
18-
RunE: run.CreateArticleFunc(&timeFlag, &name),
18+
RunE: run.CreateArticleFunc(&timeFlag, &name, &autor),
1919
Example: `note-cli create article
2020
note-cli create article --name article-a
2121
note-cli create article -t`,
@@ -24,11 +24,13 @@ note-cli create article -t`,
2424
var (
2525
timeFlag bool
2626
name string
27+
autor string
2728
)
2829

2930
func init() {
3031
articleCmd.Flags().BoolVarP(&timeFlag, "time", "t", false, "Create directory and file names with the current timestamp")
3132
articleCmd.Flags().StringVarP(&name, "name", "n", "", "Create a directory with the specified name")
33+
articleCmd.Flags().StringVarP(&autor, "author", "a", "", "Author name")
3234

3335
articleCmd.MarkFlagsMutuallyExclusive("time", "name")
3436

cmd/image.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var imageCmd = &cobra.Command{
99
Use: "image",
1010
Short: "Create title image.",
1111
Long: `Create title image`,
12+
Args: cobra.NoArgs,
1213
RunE: run.CreateImageFunc(&templateNo, &iconPath, &outputPath),
1314
}
1415

internal/file/file.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
package file
22

33
import (
4+
"bytes"
5+
"fmt"
6+
"io"
47
"os"
58
)
69

710
func Exist(filename string) bool {
811
_, err := os.Stat(filename)
912
return !os.IsNotExist(err)
1013
}
14+
15+
func Extract(r io.Reader, start, end string) ([]byte, error) {
16+
// read data
17+
b, err := io.ReadAll(r)
18+
if err != nil {
19+
return nil, err
20+
}
21+
22+
// extract content
23+
startBytes := []byte(start)
24+
endBytes := []byte(end)
25+
startIndex := bytes.Index(b, startBytes)
26+
endIndex := bytes.Index(b[startIndex+len(startBytes):], endBytes)
27+
if startIndex == -1 || endIndex == -1 {
28+
return nil, fmt.Errorf("could not find target content. start: %s end: %s", start, end)
29+
}
30+
31+
return b[startIndex+len(startBytes) : startIndex+len(startBytes)+endIndex], nil
32+
}

0 commit comments

Comments
 (0)