1
- # v0.2.1
2
- # Version Comments: First working version to be tested
1
+ # v0.2.2
2
+ # Version Comments: Starting creation of page names for each CSV table row
3
3
# Repository: https://github.com/GitMurf/csv-to-roam-table-md
4
4
# Code written by: Murf
5
5
# Design/Concept by: Rob Haisfield @RobertHaisfield on Twitter
@@ -16,10 +16,21 @@ $bulletType = "-"
16
16
# Set the delimiter variable (default is "," comma)
17
17
$strDelim = " ,"
18
18
19
+ # Add a blank line for easier reading of prompts in powershell window
20
+ Write-Host
21
+
22
+ # Ask for user input to create pages for each row, otherwise will just default to creating a single markdown file with the table markdown for Roam
23
+ $respPages = Read-Host " Do you want to create a Page for each Row in the CSV file? (Enter y or n)"
24
+
25
+ # Check if user decided to create new pages (e.g., a CRM import)
26
+ if ($respPages -eq " y" -or $respPages -eq " Y" -or $respPages -eq " yes" -or $respPages -eq " Yes" ){$bPages = $true }else {$bPages = $false }
27
+
28
+ # Add a blank line for easier reading of prompts in powershell window
29
+ Write-Host
30
+
19
31
# Ask for user input. If left blank and user presses ENTER, then continue with default (comma). Otherwise they can enter their own option.
20
32
$respDelim = Read-Host " Default CSV Delimiter is '$strDelim ' (comma). Press ENTER to Continue or input 'n' to change it."
21
33
22
- # Add a blank line for easier reading of prompts in powershell window
23
34
Write-Host
24
35
25
36
# Check if user decided to change to a different delimiter
@@ -29,7 +40,6 @@ if($respDelim -eq "n" -or $respDelim -eq "N" -or $respDelim -eq "'n'" -or $respD
29
40
if ($strDelim -eq " TAB" -or $strDelim -eq " tab" -or $strDelim -eq " 'TAB'" -or $strDelim -eq " 'tab'" ){$strDelim = " `t " }
30
41
}
31
42
32
- # Add a blank line for easier reading of prompts in powershell window
33
43
Write-Host
34
44
35
45
# Get path where script is running from so you can target CSV
@@ -38,7 +48,6 @@ $scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
38
48
# Ask for user input. If left blank and user presses ENTER, then use the script path. Otherwise they can enter their own custom path.
39
49
$respPath = Read-Host " Is your target CSV file located here: '$scriptPath '? Press ENTER to Continue or input 'n' to change it."
40
50
41
- # Add a blank line for easier reading of prompts in powershell window
42
51
Write-Host
43
52
44
53
# Check if user decided to change to a different path
@@ -47,34 +56,48 @@ if($respPath -eq "n" -or $respPath -eq "N" -or $respPath -eq "'n'" -or $respPath
47
56
$scriptPath = Read-Host " Enter the folder path of your CSV file (do NOT include the file name)"
48
57
}
49
58
50
- # Add a blank line for easier reading of prompts in powershell window
51
59
Write-Host
52
60
53
61
# Get the file name from user and create the full path
54
62
$fileNameStr = Read-Host " Name of CSV file with extension? Do NOT include path. Example: FileName.csv"
55
63
$fileNameStrPath = $scriptPath + " \" + $fileNameStr
56
64
57
- # Add a blank line for easier reading of prompts in powershell window
58
65
Write-Host
59
66
67
+ # Set the Results folder to store all the outputs from the script
68
+ $resultsFolder = " $scriptPath \Results"
69
+
60
70
# Get a date string down to the second we can add to new markdown file we will be creating so no duplicates if we run multiple times
61
71
$fullDateStr = get-date
62
72
$dateStrName = $fullDateStr.ToString (" yyyy_MM_dd-HH_mm_ss" )
63
- $newMarkdownFile = " $scriptPath \" + " $fileNameStr " + " _$dateStrName .md"
73
+ $csvFileName = " $fileNameStr " + " _$dateStrName "
74
+ $newMarkdownFile = " $resultsFolder \" + " csvFileName" + " .md"
64
75
76
+ # If $bPages -eq $true, then create the csv-import page name to store all the info about this import and the pages it creates
77
+ if ($bPages )
78
+ {
79
+ $csvImportName = " [[csv-import]] - " + $csvFileName
80
+ $csvImportNamePath = " $resultsFolder \" + " $csvImportName " + " .md"
81
+ # Create Results folder if it doesn't already exist
82
+ if (! (Test-Path $resultsFolder )){New-Item - ItemType Directory - Force - Path $resultsFolder | Out-Null }
83
+ # Write attribute for csv-import to first line of this new .md file (need to use LiteralPath parameter because of [[]] characters in path)
84
+ Add-content - LiteralPath $csvImportNamePath - value (" csv-import:: " + " [[April 25th, 2020]]" )
85
+ }
86
+ Read-Host - Prompt " Script complete. Press any key to exit."
87
+ Exit
65
88
# Import .CSV file into a Variable to loop through and parse
66
89
$csvObject = Import-Csv - Delimiter $strDelim - Path " $fileNameStrPath "
67
90
68
91
# Collapse the entire table under a parent bullet with name of the CSV file
69
92
$tableCell = " TABLE IMPORT FROM CSV: " + $fileNameStr
70
93
$tableCell = $bulletType + $tableCell
71
- Add-content $newMarkdownFile - value $tableCell
94
+ Add-content - LiteralPath $newMarkdownFile - value $tableCell
72
95
73
96
# Add {{table}}
74
97
$tableCell = " {{table}}"
75
98
$tableCell = $bulletType + $tableCell
76
99
$tableCell = $indentType + $tableCell
77
- Add-content $newMarkdownFile - value $tableCell
100
+ Add-content - LiteralPath $newMarkdownFile - value $tableCell
78
101
79
102
# Start by adding the table header to the markdown results file
80
103
$ctr = 2
@@ -90,7 +113,7 @@ foreach($col in $csvObject[0].psobject.properties.name)
90
113
$tmpCtr = $tmpCtr - 1
91
114
}
92
115
93
- Add-content $newMarkdownFile - value $tableCell
116
+ Add-content - LiteralPath $newMarkdownFile - value $tableCell
94
117
$ctr = $ctr + 1
95
118
}
96
119
@@ -113,7 +136,7 @@ foreach($row in $csvObject)
113
136
$tmpCtr = $tmpCtr - 1
114
137
}
115
138
116
- Add-content $newMarkdownFile - value $tableCell
139
+ Add-content - LiteralPath $newMarkdownFile - value $tableCell
117
140
$ctr = $ctr + 1
118
141
}
119
142
}
0 commit comments