-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateREADME.ps1
48 lines (33 loc) · 1.24 KB
/
UpdateREADME.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
$nbs = Get-ChildItem notebooks -Recurse | where-object {$_.name -like '*.ipynb'} | Sort-Object {$_.FullName} | foreach-object {$_.FullName}
$elements = @()
$elements = "`r"
$elements += "|Subject|Title|Description|Link|`r"
$elements += "| ------- | ------- | ------- | ------- |`r"
foreach($nb in $nbs)
{
if($nb -like '*.ipynb_checkpoints*')
{
continue
}
$json = ((get-content $nb) | ConvertFrom-json)
$cell = $json.cells[0].source
$cell_elements = $cell.Split([Environment]::NewLine)
$cell_elements = $cell_elements | Where-Object({($_ -ne '')})
$title = $cell_elements[0].replace("# ","")
$desc = $cell_elements[1]
if($desc.Length -gt 99)
{
$desc = $desc.Substring(0, 100)
}
$path = ($nb | Resolve-Path -Relative).replace(".\","").replace("\","/")
$subject = $path.split("/")[1]
$new = "|<sub>" + $subject +"</sub>|<sub>" + $title + "</sub>|<sub>" + $desc + "...</sub>|<sub>[" + $path + "](" + $path + ")</sub>|`r"
$elements += $new
}
$pattern_end = "## Table of contents:"
$readme = (get-content README.md)
$end_pos = $readme.IndexOf($pattern_end)
$readme = $readme[0..$end_pos] -join "`r"
$new_readme = "$readme
$elements"
$new_readme | Out-File README.md -Force