[obsidian] vault backup: 2024-02-08 19:14:51[
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build / build (push) Successful in 1m43s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build / build (push) Successful in 1m43s
				
			This commit is contained in:
		| @@ -1,29 +1,28 @@ | ||||
| #!/bin/bash | ||||
| #別のマシンで作ったファイルはわからんので、それぞれのでやって古い方で上書きする必要がある | ||||
| cwd=`dirname "${0}"` | ||||
| function rewritedate () { | ||||
| 	echo "$1 : $2" | ||||
| 	echo $2 | xargs -I{} yq -i --front-matter="process" '.date="{}"' "$1" | ||||
| } | ||||
| FILES=$(find $cwd/content -name "*.md") | ||||
| IFS=$'\n' | ||||
| for f in $FILES | ||||
| do | ||||
| BDATE=$(stat -f "%SB" "$f"); | ||||
| DATE=$(LC_ALL=C date -j -Iseconds -f "%b %d %H:%M:%S %Y" "$BDATE"); | ||||
| FLINE=$(head -n 1 "$f"); | ||||
| if [[ "$FLINE" == "---" ]]; | ||||
| then | ||||
| echo "$f has frontmatter"; | ||||
| ORIGINDATE=$(yq --front-matter=extract '.date' "$f" | date "+%s") | ||||
| LOCALDATE=$(LC_ALL=C date -j -f "%b %d %H:%M:%S %Y" "$BDATE" | date "+%s"); | ||||
|  | ||||
| if [ $LOCALDATE -lt $ORIGINDATE ]; then # -lt : '<' | ||||
|     echo "date of local file is older. overwriting." | ||||
|     DATE=$(LC_ALL=C date -j -Iseconds -f "%b %d %H:%M:%S %Y" "$BDATE"); | ||||
|     echo "$f : $DATE" | ||||
|     echo $DATE | xargs -I{} yq -i --front-matter="process" '.date="{}"' "$f" | ||||
| GITDATE=$(git blame $f | grep -Eo '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}'| xargs -I{} date -j -f "%Y-%m-%d %H:%M:%S" "{}" | date "+%s"); | ||||
| if [[ "$FLINE" == "---" ]]; | ||||
| then | ||||
| if [ $LOCALDATE -lt $ORIGINDATE ]; then  | ||||
|     echo "$f has frontmatter and date of local file is older. overwriting." | ||||
|     rewritedate $f $BDATE | ||||
| fi | ||||
| else | ||||
| echo "$f has no frontmatter, adding"; | ||||
| echo "$f has no frontmatter, adding to it"; | ||||
| gsed -i '1i---\n---' "$f" | ||||
| DATE=$(LC_ALL=C date -j -Iseconds -f "%b %d %H:%M:%S %Y" "$BDATE"); | ||||
| echo "$f : $DATE" | ||||
| echo $DATE | xargs -I{} yq -i --front-matter="process" '.date="{}"' "$f" | ||||
| rewritedate $f $DATE | ||||
| fi | ||||
| done | ||||
| @@ -1,5 +1,5 @@ | ||||
| --- | ||||
| date: "2024-02-08T17:35:58+09:00" | ||||
| date: "2024-02-08T17:46:04+09:00" | ||||
| --- | ||||
| #book #ace | ||||
|  | ||||
|   | ||||
| @@ -17,33 +17,31 @@ date: "2024-02-08T17:18:56+09:00" | ||||
|  | ||||
| ```bash | ||||
| #!/bin/bash | ||||
| #別のマシンで作ったファイルのBirth Dateはわからんので、それぞれのマシンで実行して古い方で上書きする | ||||
| cwd=`dirname "${0}"` | ||||
| function rewritedate () { | ||||
| 	echo "$1 : $2" | ||||
| 	echo $2 | xargs -I{} yq -i --front-matter="process" '.date="{}"' "$1" | ||||
| } | ||||
| FILES=$(find $cwd/content -name "*.md") | ||||
| IFS=$'\n' | ||||
| for f in $FILES | ||||
| do | ||||
| BDATE=$(stat -f "%SB" "$f"); | ||||
| FLINE=$(head -n 1 "$f"); | ||||
| if [[ "$FLINE" == "---" ]]; | ||||
| then | ||||
| echo "$f has frontmatter"; | ||||
| ORIGINDATE=$(yq --front-matter=extract '.date' "$f" | date "+%s") | ||||
| LOCALDATE=$(LC_ALL=C date -j -f "%b %d %H:%M:%S %Y" "$BDATE" | date "+%s"); | ||||
|  | ||||
| if [ $LOCALDATE -lt $ORIGINDATE ]; then #古い方で上書き | ||||
|     echo "date of local file is older. overwriting." | ||||
| if [[ "$FLINE" == "---" ]]; | ||||
| then | ||||
| if [ $LOCALDATE -lt $ORIGINDATE ]; then  | ||||
|     echo "$f has frontmatter and date of local file is older. overwriting." | ||||
|     DATE=$(LC_ALL=C date -j -Iseconds -f "%b %d %H:%M:%S %Y" "$BDATE"); | ||||
|     echo "$f : $DATE" | ||||
|     echo $DATE | xargs -I{} yq -i --front-matter="process" '.date="{}"' "$f" | ||||
|     rewritedate $f $BDATE | ||||
| fi | ||||
| #フロントマターがあって、その日付が最古なら何もしない | ||||
| else | ||||
| echo "$f has no frontmatter, adding"; | ||||
| gsed -i '1i---\n---' "$f" | ||||
| echo "$f has no frontmatter, adding to it"; | ||||
| DATE=$(LC_ALL=C date -j -Iseconds -f "%b %d %H:%M:%S %Y" "$BDATE"); | ||||
| echo "$f : $DATE" | ||||
| echo $DATE | xargs -I{} yq -i --front-matter="process" '.date="{}"' "$f" | ||||
| gsed -i '1i---\n---' "$f" | ||||
| rewritedate $f $DATE | ||||
| fi | ||||
| done | ||||
| ``` | ||||
|   | ||||
		Reference in New Issue
	
	Block a user