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