-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprintkeep.ps1
53 lines (44 loc) · 1.26 KB
/
printkeep.ps1
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
41
42
43
44
45
46
47
48
49
50
51
52
53
<#
.SYNOPSIS
Outputs nice content of Google Keep notes
.PARAMETER File
Filename. If starts with year, not printed
.PARAMETER Creation
Prints creation date in YAML front matter
#>
param(
[Parameter(Mandatory=$true)]
[string] $File,
[switch] $Creation = $false
)
$script:ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
$item = Get-Item $File
$content = Get-Content -Raw $File
$base = $item.BaseName
if ($content -match "aliases:`n - `"(.*)`"`n") {
"## " + $matches[1]
} elseif (-not ($base -match '^20\d\d-\d\d-\d\dT')) {
"## " + $base
} else {
"`n---"
}
if ($content.StartsWith("---")) {
$content = $content -split '---' | Select-Object -skip 2
}
if ($Creation) {
"---"
"created: $($item.CreationTime.ToString('yyyy-MM-dd'))"
"---"
}
# "## $($item.CreationTime.ToString('yyyy-MM-dd'))"
$content.Trim()
"`n---`n"
# NOT NEEDED: just symlink Assets/ into vault
# # Find link like ![[18cc06d7b0f.a8b6c61df584a88d.png]] and copy attachment
# foreach ($match in [regex]::Matches($content, '!\[\[(.*?)\]\]')) {
# $noteAttachments = "~/notes/MyNotes/KeepAttachments"
# mkdir -p $noteAttachments
# $attachment = $match.Groups[1].Value
# Copy-Item -Force (Join-Path $item.DirectoryName Assets $attachment) "$noteAttachments/$attachment"
# }