-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-user-file-uploads.sh
40 lines (36 loc) · 1.31 KB
/
generate-user-file-uploads.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
targetDir=$1
csvPath="$targetDir/upload.csv"
crnl="\r\n"
rm -f "$csvPath"
touch "$csvPath"
printf "uesio/core.recordid,uesio/core.fieldid,uesio/core.path,uesio/core.sourcepath$crnl" >> $csvPath
# We expect a structure where files are nested at a max of 2 levels,
# e.g.
# files
# ├── first-app
# │ ├── createroute.png
# │ ├── suggestfields.png
# │ └── first-app.md
# │ create-account.md
#
# We expect that any NON-markdown files, e.g. PNG / JPG,
# would be nested within a folder that has the same name as the markdown file
# to which the image is related and should be attached,
# e.g. "first-app/createroute.png" is related to "first-app.md"
#
# However, Markdown filese can be buried either within a folder,
# or they can be nested within their category directory.
for file in $(find "$targetDir/files" -type f -maxdepth 3)
do
relative_path=${file#"$targetDir/files/"}
basefile=$(basename -- "$file")
filename="${basefile%.*}"
if [[ $file == *".md" ]]; then
printf "$filename,uesio/cms.content,$basefile,$relative_path$crnl" >> $csvPath
else
# we need to get the dirname to know where to attach it to
dirname=$(basename $(dirname "$file"))
printf "$dirname,,$basefile,$relative_path$crnl" >> $csvPath
fi
done