39
39
white : \033[:1;37m
40
40
nocolor : \u001b[0m
41
41
reversed : \u001b[7m
42
+ CODE_CONFIG : .code-config
43
+
42
44
tasks :
43
45
default :
44
46
cmds :
@@ -166,12 +168,22 @@ tasks:
166
168
echo -e "{{ .dark_gray }} creating new file: $filename {{ .nocolor }}"
167
169
hugo new $filename --kind blog
168
170
echo -e "{{ .green }} ✅ created: $filename {{ .nocolor }}"
169
- microblog :
170
- desc : Create a new microblog post
171
- cmds :
171
+ 100daysofcode_readconfig :
172
+ desc : read the counter values for 100 days of code to simplify creation from archetype
173
+ cmds :
174
+ - |
175
+ source {{ .CODE_CONFIG }}
176
+ echo -e "{{.light_gray}}=== ℹ {{ .reversed }} 100 Days Of Code Config from: [{{ .CODE_CONFIG}}] {{ .nocolor }} === "
177
+ echo -e "{{.light_gray}}LANGUAGE {{.nocolor}}: {{ .orange}} $LANGUAGE {{ .nocolor }}"
178
+ echo -e "{{.light_gray}}ROUND {{.nocolor}}: {{ .orange}} $ROUND {{ .nocolor }}"
179
+ echo -e "{{.light_gray}}COUNTER {{.nocolor}}: {{ .orange}} $COUNTER {{ .nocolor }}"
180
+ post :
181
+ desc : Create a new post
182
+ cmds :
183
+ - task : 100daysofcode_readconfig
172
184
- |
173
185
echo -e "{{.light_gray}}=== ℹ {{ .reversed }} Variable Info from Task {{ .nocolor }} === "
174
- echo -e "{{.light_gray}}TODAY_UTC {{.nocolor}}: {{ .orange}}{{ .TODAY_UTC }} {{ .nocolor }}"
186
+ echo -e "{{.light_gray}}TODAY_UTC {{.nocolor}}: {{ .orange}}{{ .TODAY_UTC }} {{ .nocolor }}"
175
187
echo -e "{{.green}}Please enter title{{ .nocolor }}"
176
188
read;
177
189
echo -e "{{.green}}Title: ${REPLY}{{ .nocolor }}"
@@ -180,29 +192,47 @@ tasks:
180
192
| sed 's/[[:space:]]*//g' \
181
193
| tr '[:upper:]' '[:lower:]'
182
194
)
183
- directory=./content/microblog/
184
- mkdir -p $directory/{{ .YEAR }} || echo -e "{{.dark_gray}}🔄 skipped creation of directory [$directory] per already exists {{.nocolor}}"
185
- filename=$directory/{{ .YEAR }}/{{ .YEAR }}-{{ .MONTH }}-{{ .DAY }}-$title.md
186
- echo -e "{{ .dark_gray }} creating new file: $filename {{ .nocolor }}"
187
- hugo new $filename --kind microblog
188
- echo -e "{{ .green }} ✅ created: $filename {{ .nocolor }}"
189
- code :
190
- desc : Create a new 100DaysOfCode post
191
- cmds :
192
- - |
193
- echo -e "{{.light_gray}}=== ℹ {{ .reversed }} Variable Info from Task {{ .nocolor }} === "
194
- echo -e "{{.light_gray}}TODAY_UTC {{.nocolor}}: {{ .orange}}{{ .TODAY_UTC }} {{ .nocolor }}"
195
- echo -e "{{.green}}Please enter title{{ .nocolor }}"
195
+ echo -e "{{.green}}Please enter [blog, microblog, code] for archetype{{ .nocolor }}"
196
196
read;
197
- echo -e "{{.green}}Title: ${REPLY}{{ .nocolor }}"
198
- title=$(echo ${REPLY} \
199
- | sed 's/\(.\)\([A-Z]\)/\1-\2/g' \
200
- | sed 's/[[:space:]]*//g' \
201
- | tr '[:upper:]' '[:lower:]'
202
- )
203
- directory=./content/microblog/
197
+ archetype=$(echo ${REPLY})
198
+
199
+ directory=./content/posts/
204
200
mkdir -p $directory/{{ .YEAR }} || echo -e "{{.dark_gray}}🔄 skipped creation of directory [$directory] per already exists {{.nocolor}}"
205
- filename=$directory/{{ .YEAR }}/{{ .YEAR }}-{{ .MONTH }}-{{ .DAY }}-$title.md
201
+ filename=$directory{{ .YEAR }}/{{ .YEAR }}-{{ .MONTH }}-{{ .DAY }}-$title.md
202
+
203
+ if [[ $archetype == "code" ]];
204
+ then
205
+ source {{ .CODE_CONFIG }}
206
+ echo -e "{{.light_gray}}=== ℹ {{ .reversed }} 100 Days Of Code Config from: [{{ .CODE_CONFIG}}] {{ .nocolor }} === "
207
+ echo -e "{{.light_gray}}LANGUAGE {{.nocolor}}: {{ .orange}} $LANGUAGE {{ .nocolor }}"
208
+ echo -e "{{.light_gray}}ROUND {{.nocolor}}: {{ .orange}} $ROUND {{ .nocolor }}"
209
+ echo -e "{{.light_gray}}COUNTER {{.nocolor}}: {{ .orange}} $COUNTER {{ .nocolor }}"
210
+ UPDATED_COUNTER=$(($COUNTER+1))
211
+ TARGET_KEY=COUNTER
212
+ REPLACEMENT_VALUE=$UPDATED_COUNTER
213
+ sed -i '' "s/\($TARGET_KEY *= *\).*/\1$REPLACEMENT_VALUE/" "{{ .CODE_CONFIG }}"
214
+ echo -e "{{.green}} 💾 updated code config with new counter: from [$COUNTER] to [$UPDATED_COUNTER] (saved in {{ .CODE_CONFIG }}){{ .nocolor }}"
215
+ echo -e "{{.dark_gray}} ℹ override filename with 100days of code naming convention{{ .nocolor }}"
216
+ filename=$directory/{{ .YEAR }}/{{ .YEAR }}-{{ .MONTH }}-{{ .DAY }}-$LANGUAGE-R$ROUND-day-$UPDATED_COUNTER.md
217
+ hugo new $filename --kind $archetype
218
+
219
+ # Replace the counter in the text file
220
+ sed -i '' "s/VAR_LANGUAGE/$LANGUAGE/g" "$filename"
221
+ sed -i '' "s/VAR_ROUND/$ROUND/g" "$filename"
222
+ sed -i '' "s/VAR_DAYCOUNTER/$UPDATED_COUNTER/g" "$filename"
223
+ echo -e "{{.dark_gray}} 💾 update VAR_DAYCOUNTER,VAR_LANGUAGE,VAR_DAY_COUNTER in output file{{ .nocolor }}"
224
+ else
225
+ hugo new $filename --kind $archetype
226
+ fi
206
227
echo -e "{{ .dark_gray }} creating new file: $filename {{ .nocolor }}"
207
- hugo new $filename --kind 100DaysOfCode
208
- echo -e "{{ .green }} ✅ created: $filename {{ .nocolor }}"
228
+ echo -e "{{ .green }} ✅ created [ $archetype ] at: [ $filename ] {{ .nocolor }}"
229
+ bear :
230
+ desc : Run bhugo to sync posts
231
+ cmds :
232
+ - |
233
+ echo -e "{{.light_gray}}=== ℹ {{ .reversed }} Running Bear Hugo {{ .nocolor }} === "
234
+ go get -u github.com/Zach-Johnson/bhugo
235
+ bhugo
236
+ preconditions :
237
+ - test -f .bhugo
238
+ # TODO: Add task for imageoptim preprocessing on staged files only
0 commit comments