Skip to content

Commit e4dc3f5

Browse files
committed
first steps towards global index, updated cloud-examples
1 parent acb9058 commit e4dc3f5

File tree

6 files changed

+91
-10
lines changed

6 files changed

+91
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
index.json

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@ This mainly adds a categorization and meta-description layer on top of this and
44

55
## Indexing
66

7-
Nothing done yet, probably a simple `make` will call a script.
7+
Call `./index.py` or just do a simple `make` to call that script.
88

99
## Datamodel
1010

11-
* Goal: JSON for the SMC UI, such that user can select templates -- no need to think about the specific representation, only the elements that are the actually moving parts for such a selector.
11+
* Goal: autogenerated JSON for the SMC UI, such that user can select templates -- no need to think about the specific representation, only the elements that are the actually moving parts for such a selector.
1212

13-
* Parts
14-
* Filename/Directoryname
15-
* Title
16-
* Description
17-
* Tags for categorization
18-
* Centralized description of tags (?)
13+
* YAML Document Types
14+
15+
* first document: metadata
16+
* description of tags
17+
* description of license
18+
* references: point to another index description file
19+
* remaining documents are for each indexed entry:
20+
* Target: Filename/Directory
21+
* Title
22+
* Description
23+
* Tags for categorization
24+
* license
1925

2026
## Devnotes
2127

@@ -29,6 +35,9 @@ If you want to update all submodules in one go, do something like
2935

3036
## License
3137

32-
Unless otherwise noted, Apache 2.0
38+
Unless otherwise noted,
39+
[Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0) for code and
40+
[CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
41+
for content.
3342

3443

cloud-examples

index.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python3
2+
# Copyright: Harald Schilly <hsy@sagemath.com>
3+
# License: Apache 2.0
4+
from pprint import pprint
5+
import yaml
6+
import json
7+
import os
8+
os.chdir(os.path.dirname(os.path.abspath(__file__)))
9+
10+
def update_meta(meta, new_meta):
11+
'''
12+
A simple dict update would overwrite/remove entries.
13+
'''
14+
if 'tags' in new_meta:
15+
meta['tags'].update(new_meta['tags'])
16+
if 'licenses' in new_meta:
17+
meta['licenses'].update(new_meta['licenses'])
18+
19+
def resolve_references(meta, docs):
20+
# append new documents and merge meta
21+
if 'references' in meta:
22+
for ref in meta['references']:
23+
new_meta, *new_docs = yaml.load_all(open(ref))
24+
resolve_references(new_meta, new_docs)
25+
update_meta(meta, new_meta)
26+
docs.extend(new_docs)
27+
del meta['references']
28+
return meta, docs
29+
30+
def debug(meta, docs):
31+
print("META:")
32+
pprint(meta)
33+
print("DOCS:")
34+
for doc in docs:
35+
pprint(doc)
36+
37+
def export_json(meta, docs):
38+
with open('index.json', 'w') as out:
39+
json.dump({'metadata': meta, 'documents': docs}, out, indent=1)
40+
41+
def main(index_fn):
42+
meta, *docs = yaml.load_all(open(index_fn))
43+
resolve_references(meta, docs)
44+
debug(meta, docs)
45+
export_json(meta, docs)
46+
47+
if __name__ == '__main__':
48+
main(index_fn = 'index.yaml')

index.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
tags:
3+
calc: Calculus
4+
linalg: Linear Algebra
5+
stats: Statistics
6+
licenses:
7+
ccby: CC BY 4.0
8+
asis: AS IS
9+
references:
10+
- cloud-examples/index.yaml
11+
---
12+
target: bayesian-methods-for-hackers/
13+
title: Bayesian Methods for Hackers
14+
description: |
15+
Hands-on tutorial how Bayesian Methods work, based on Python's PyMC library.
16+
author: Cameron Davidson-Pilon
17+
license: asis
18+
tags:
19+
- stats

makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
PHONY = update
22

3+
default: index
4+
35
update:
46
git submodule foreach "git checkout master; git pull origin master"
57

8+
index:
9+
./index.py

0 commit comments

Comments
 (0)