Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework cookbook #149

Merged
merged 29 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
662fb05
Reformat existing cookbooks to use the table layout for the recipe+js…
digitaldogsbody Dec 24, 2022
15759b5
Add mkdocs-awesome-pages and configure it to automatically add the co…
digitaldogsbody Dec 24, 2022
8f3d4b5
Add brief recipes introduction and update the docs nav
digitaldogsbody Dec 24, 2022
8890ae2
Move all cookbook python to individual files and update recipe markdo…
digitaldogsbody Dec 24, 2022
3e251be
Update mkdocs to use pymdownx snippets
digitaldogsbody Dec 24, 2022
2b92935
First pass cookbook testing utility
digitaldogsbody Dec 27, 2022
3413149
Lint recipe file, mark regex strings as raw, add qa ignore for functi…
digitaldogsbody Dec 27, 2022
4aa35a0
Lint recipes
digitaldogsbody Dec 27, 2022
a098ed9
Update recipes to correct errors discovered by the new tool
digitaldogsbody Dec 27, 2022
262d202
Update existing recipes to make use of the new `anno_id` and `anno_pa…
digitaldogsbody Dec 27, 2022
005efb3
Add deepdiff to the dev dependencies
digitaldogsbody Dec 27, 2022
659beef
First pass recipe checker workflow
digitaldogsbody Dec 27, 2022
2924e13
Make sure cache directory exists and remove unimplemented `--no-cache…
digitaldogsbody Dec 27, 2022
4823d44
Use the correct arg name (oops!)
digitaldogsbody Dec 27, 2022
77618c6
Update workflow to fail on missing files
digitaldogsbody Dec 27, 2022
956a92f
Add recipe but not script to test failure
digitaldogsbody Dec 27, 2022
316b44a
Stop script matching JSON group to test `--fail-missing`
digitaldogsbody Dec 27, 2022
71d4afa
Change the script back to the correct location
digitaldogsbody Dec 27, 2022
b66b4a3
Update auto_helper to apply AutoLabel to the `Class` meta-class, sinc…
digitaldogsbody Dec 27, 2022
0eaf219
Correct recipe description
digitaldogsbody Dec 27, 2022
20249cb
Add 0017 script
digitaldogsbody Dec 27, 2022
943a78a
Import and use Pydantic's JSON encoder function to ensure we can seri…
digitaldogsbody Jan 2, 2023
401760f
Add 0230-navdate recipe
digitaldogsbody Jan 2, 2023
8bb8777
Update cookbook test script regexes
digitaldogsbody Jan 2, 2023
e2e2c44
Fix bug with `insert` changetype
digitaldogsbody Jan 2, 2023
4f2e2a0
Add extra properties on ManifestRef changeset
digitaldogsbody Jan 2, 2023
b4dcf1b
Update skeleton
digitaldogsbody Jan 2, 2023
1654385
Update auto_helper to apply AutoLabel to the `Reference` meta-class
digitaldogsbody Jan 2, 2023
5b3a78b
Add second method to 0230 recipe
digitaldogsbody Jan 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/recipes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: recipes

on: [pull_request, workflow_dispatch]

permissions:
contents: read

jobs:
test-recipes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: 3.9
architecture: x64

- uses: actions/cache@v3
with:
path: |
${{ env.pythonLocation }}
iiif-prezi3/iiif-prezi3/utils/.cache
key: ${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}

- name: Install dev dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
pip install -e .[dev]

- name: Run the Recipe Check script
run: |
cd utils
python test_cookbook.py -y -v --fail-fast --fail-missing ../docs/recipes/*.md
50 changes: 9 additions & 41 deletions docs/recipes/0001-mvm-image.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,16 @@
# Simplest Manifest - Single Image File
### Recipe: [https://iiif.io/api/cookbook/recipe/0001-mvm-image/](https://iiif.io/api/cookbook/recipe/0001-mvm-image/)
### JSON-LD: [https://iiif.io/api/cookbook/recipe/0001-mvm-image/manifest.json](https://iiif.io/api/cookbook/recipe/0001-mvm-image/manifest.json)
| | **Cookbook URLs** |
|--------------|----------------------------------------------------------------------|
| **Recipe:** | [https://iiif.io/api/cookbook/recipe/0001-mvm-image/](https://iiif.io/api/cookbook/recipe/0001-mvm-image/) |
| **JSON-LD:** | [https://iiif.io/api/cookbook/recipe/0001-mvm-image/manifest.json](https://iiif.io/api/cookbook/recipe/0001-mvm-image/manifest.json) |

## Method 1 - Using the `make_canvas` and `add_image` helpers
```python
from iiif_prezi3 import Manifest, config

config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"

manifest = Manifest(id="https://iiif.io/api/cookbook/recipe/0001-mvm-image/manifest.json", label="Image 1")
canvas = manifest.make_canvas(id="https://iiif.io/api/cookbook/recipe/0001-mvm-image/canvas/p1", height=1800, width=1200)
anno_page = canvas.add_image(image_url="http://iiif.io/api/presentation/2.1/example/fixtures/resources/page1-full.png",
anno_page_id="https://iiif.io/api/cookbook/recipe/0001-mvm-image/page/p1/1",
anno_id="https://iiif.io/api/cookbook/recipe/0001-mvm-image/annotation/p0001-image",
format="image/png",
height=1800,
width=1200
)

print(manifest.json(indent=2))
### Method 1 - Using the `make_canvas` and `add_image` helpers
```python
--8<-- "docs/recipes/scripts/0001-mvm-image-method1.py"
```

## Method 2 - Building the structure manually and using the `add_item` helper
### Method 2 - Building the structure manually and using the `add_item` helper
```python
from iiif_prezi3 import Manifest, Canvas, AnnotationPage, Annotation, ResourceItem, config

config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"

manifest = Manifest(id="https://iiif.io/api/cookbook/recipe/0001-mvm-image/manifest.json", label="Image 1")
canvas = Canvas(id="https://iiif.io/api/cookbook/recipe/0001-mvm-image/canvas/p1", height=1800, width=1200)
anno_body = ResourceItem(id="http://iiif.io/api/presentation/2.1/example/fixtures/resources/page1-full.png",
type="Image",
format="image/png",
height=1800,
width=1200)
anno_page = AnnotationPage(id="https://iiif.io/api/cookbook/recipe/0001-mvm-image/page/p1/1")
anno = Annotation(id="https://iiif.io/api/cookbook/recipe/0001-mvm-image/annotation/p0001-image",
motivation="painting",
body=anno_body,
target=canvas.id)
anno_page.add_item(anno)
canvas.add_item(anno_page)
manifest.add_item(canvas)

print(manifest.json(indent=2))
--8<-- "docs/recipes/scripts/0001-mvm-image-method2.py"
```

28 changes: 6 additions & 22 deletions docs/recipes/0002-mvm-audio.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
# Simplest Manifest - Audio
### Recipe: [https://iiif.io/api/cookbook/recipe/0002-mvm-audio/](https://iiif.io/api/cookbook/recipe/0002-mvm-audio/)
### JSON-LD: [https://iiif.io/api/cookbook/recipe/0002-mvm-audio/manifest.json](https://iiif.io/api/cookbook/recipe/0002-mvm-audio/manifest.json)
| | **Cookbook URLs** |
|--------------|--------------------------------------------------------------------------------------------------------------------------------------|
| **Recipe:** | [https://iiif.io/api/cookbook/recipe/0002-mvm-audio/](https://iiif.io/api/cookbook/recipe/0002-mvm-audio/) |
| **JSON-LD:** | [https://iiif.io/api/cookbook/recipe/0002-mvm-audio/manifest.json](https://iiif.io/api/cookbook/recipe/0002-mvm-audio/manifest.json) |

## Method 1 - Building the structure and using the `add_item` helper
### Method 1 - Building the structure and using the `add_item` helper
```python
from iiif_prezi3 import Manifest, AnnotationPage, Annotation, ResourceItem, config

config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"

manifest = Manifest(id="https://iiif.io/api/cookbook/recipe/0002-mvm-audio/manifest.json", label="Simplest Audio Example")
canvas = manifest.make_canvas(id="https://iiif.io/api/cookbook/recipe/0002-mvm-audio/canvas", duration=1985.024)
anno_body = ResourceItem(id="https://fixtures.iiif.io/audio/indiana/mahler-symphony-3/CD1/medium/128Kbps.mp4",
type="Sound",
format="audio/mp4",
duration=1985.024)
anno_page = AnnotationPage(id="https://iiif.io/api/cookbook/recipe/0002-mvm-audio/canvas/page")
anno = Annotation(id="https://iiif.io/api/cookbook/recipe/0002-mvm-audio/canvas/page/annotation",
motivation="painting",
body=anno_body,
target=canvas.id)
anno_page.add_item(anno)
canvas.add_item(anno_page)

print(manifest.json(indent=2))
--8<-- "docs/recipes/scripts/0002-mvm-audio-method1.py"
```
32 changes: 6 additions & 26 deletions docs/recipes/0003-mvm-video.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
# Simplest Manifest - Video
### Recipe: [https://iiif.io/api/cookbook/recipe/0003-mvm-video/](https://iiif.io/api/cookbook/recipe/0003-mvm-video/)
### JSON-LD: [https://iiif.io/api/cookbook/recipe/0003-mvm-video/manifest.json](https://iiif.io/api/cookbook/recipe/0003-mvm-video/manifest.json)
| | **Cookbook URLs** |
|--------------|--------------------------------------------------------------------------------------------------------------------------------------|
| **Recipe:** | [https://iiif.io/api/cookbook/recipe/0003-mvm-video/](https://iiif.io/api/cookbook/recipe/0003-mvm-video/) |
| **JSON-LD:** | [https://iiif.io/api/cookbook/recipe/0003-mvm-video/manifest.json](https://iiif.io/api/cookbook/recipe/0003-mvm-video/manifest.json) |

## Method 1 - Building the structure manually and using the `add_item` helper
### Method 1 - Building the structure manually and using the `add_item` helper
```python
from iiif_prezi3 import Manifest, AnnotationPage, Annotation, ResourceItem, config

config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"

manifest = Manifest(id="https://iiif.io/api/cookbook/recipe/0003-mvm-video/manifest.json", label="Video Example 3")
canvas = manifest.make_canvas(id="https://iiif.io/api/cookbook/recipe/0003-mvm-video/canvas")
anno_body = ResourceItem(id="https://fixtures.iiif.io/video/indiana/lunchroom_manners/high/lunchroom_manners_1024kb.mp4",
type="Video",
format="video/mp4")
anno_page = AnnotationPage(id="https://iiif.io/api/cookbook/recipe/0003-mvm-video/canvas/page")
anno = Annotation(id="https://iiif.io/api/cookbook/recipe/0003-mvm-video/canvas/page/annotation",
motivation="painting",
body=anno_body,
target=canvas.id)

hwd = {"height": 360, "width": 480, "duration": 572.034}
anno_body.set_hwd(**hwd)
canvas.set_hwd(**hwd)

anno_page.add_item(anno)
canvas.add_item(anno_page)

print(manifest.json(indent=2))
--8<-- "docs/recipes/scripts/0003-mvm-video-method1.py"
```
31 changes: 6 additions & 25 deletions docs/recipes/0004-canvas-size.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
# Image and Canvas with Differing Dimensions
### Recipe: [https://iiif.io/api/cookbook/recipe/0004-canvas-size/](https://iiif.io/api/cookbook/recipe/0004-canvas-size/)
### JSON-LD: [https://iiif.io/api/cookbook/recipe/0004-canvas-size/manifest.json](https://iiif.io/api/cookbook/recipe/0004-canvas-size/manifest.json)
| | **Cookbook URLs** |
|--------------|------------------------------------------------------------------------------------------------------------------------------------------|
| **Recipe:** | [https://iiif.io/api/cookbook/recipe/0004-canvas-size/](https://iiif.io/api/cookbook/recipe/0004-canvas-size/) |
| **JSON-LD:** | [https://iiif.io/api/cookbook/recipe/0004-canvas-size/manifest.json](https://iiif.io/api/cookbook/recipe/0004-canvas-size/manifest.json) |

## Method 1 - Using the `set_hwd` helper
### Method 1 - Using the `set_hwd` helper
```python
from iiif_prezi3 import Manifest, AnnotationPage, Annotation, ResourceItem, config

config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"

manifest = Manifest(id="https://iiif.io/api/cookbook/recipe/0004-canvas-size/manifest.json", label="Still image from an opera performance at Indiana University")
canvas = manifest.make_canvas(id="https://iiif.io/api/cookbook/recipe/0004-canvas-size/canvas/p1")
anno_body = ResourceItem(id="https://fixtures.iiif.io/video/indiana/donizetti-elixir/act1-thumbnail.png",
type="Image",
format="image/png")
anno_page = AnnotationPage(id="https://iiif.io/api/cookbook/recipe/0004-canvas-size/canvas/page/p1/1")
anno = Annotation(id="https://iiif.io/api/cookbook/recipe/0004-canvas-size/annotation/p0001-image",
motivation="painting",
body=anno_body,
target=canvas.id)

anno_body.set_hwd(height=360, width=640)
canvas.set_hwd(height=1080, width=1920)

anno_page.add_item(anno)
canvas.add_item(anno_page)

print(manifest.json(indent=2))
--8<-- "docs/recipes/scripts/0004-canvas-size-method1.py"
```
21 changes: 6 additions & 15 deletions docs/recipes/0005-image-service.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
# Support Deep Viewing with Basic Use of a IIIF Image Service
### Recipe: [https://iiif.io/api/cookbook/recipe/0005-image-service/](https://iiif.io/api/cookbook/recipe/0005-image-service/)
### JSON-LD: [https://iiif.io/api/cookbook/recipe/0005-image-service/manifest.json](https://iiif.io/api/cookbook/recipe/0005-image-service/manifest.json)
| | **Cookbook URLs** |
|--------------|----------------------------------------------------------------------------------------------------------------------------------------------|
| **Recipe:** | [https://iiif.io/api/cookbook/recipe/0005-image-service/](https://iiif.io/api/cookbook/recipe/0005-image-service/) |
| **JSON-LD:** | [https://iiif.io/api/cookbook/recipe/0005-image-service/manifest.json](https://iiif.io/api/cookbook/recipe/0005-image-service/manifest.json) |

## Method 1 - Using the `make_canvas_from_iiif` helper
### Method 1 - Using the `make_canvas_from_iiif` helper
```python
from iiif_prezi3 import Manifest, config

config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"

manifest = Manifest(id="https://iiif.io/api/cookbook/recipe/0005-image-service/manifest.json", label="Picture of Göttingen taken during the 2019 IIIF Conference")
canvas = manifest.make_canvas_from_iiif(url="https://iiif.io/api/image/3.0/example/reference/918ecd18c2592080851777620de9bcb5-gottingen",
id="https://iiif.io/api/cookbook/recipe/0005-image-service/canvas/p1",
label="Canvas with a single IIIF image")
canvas.items[0].id = "https://iiif.io/api/cookbook/recipe/0005-image-service/page/p1/1"
canvas.items[0].items[0].id = "https://iiif.io/api/cookbook/recipe/0005-image-service/annotation/p0001-image"

print(manifest.json(indent=2))
--8<-- "docs/recipes/scripts/0005-image-service-method1.py"
```

29 changes: 6 additions & 23 deletions docs/recipes/0006-text-language.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
# Internationalization and Multi-language Values
### Recipe: [https://iiif.io/api/cookbook/recipe/0006-text-language/](https://iiif.io/api/cookbook/recipe/0006-text-language/)
### JSON-LD: [https://iiif.io/api/cookbook/recipe/0006-text-language/manifest.json](https://iiif.io/api/cookbook/recipe/0006-text-language/manifest.json)
| | **Cookbook URLs** |
|--------------|----------------------------------------------------------------------------------------------------------------------------------------------|
| **Recipe:** | [https://iiif.io/api/cookbook/recipe/0006-text-language/](https://iiif.io/api/cookbook/recipe/0006-text-language/) |
| **JSON-LD:** | [https://iiif.io/api/cookbook/recipe/0006-text-language/manifest.json](https://iiif.io/api/cookbook/recipe/0006-text-language/manifest.json) |

## Method 1 - Construct the language dictionaries during object creation
### Method 1 - Construct the language dictionaries during object creation
```python
from iiif_prezi3 import Manifest, KeyValueString

manifest = Manifest(id="https://iiif.io/api/cookbook/recipe/0006-text-language/manifest.json",
label={"en": ["Whistler's Mother"], "fr": ["La Mère de Whistler"]})
manifest.metadata = [
KeyValueString(label={"en": ["Creator"], "fr": ["Auteur"]}, value="Whistler, James Abbott McNeill"),
KeyValueString(label={"en": ["Subject"], "fr": ["Sujet"]},
value={"en": ["McNeill Anna Matilda, mother of Whistler (1804-1881)"],
"fr": ["McNeill Anna Matilda, mère de Whistler (1804-1881)"]})
]
manifest.summary = {"en": ["Arrangement in Grey and Black No. 1, also called Portrait of the Artist's Mother."],
"fr": ["Arrangement en gris et noir n°1, also called Portrait de la mère de l'artiste."]}
manifest.requiredStatement = KeyValueString(label={"en": ["Held By"], "fr": ["Détenu par"]}, value="Musée d'Orsay, Paris, France")

canvas = manifest.make_canvas_from_iiif(url="https://iiif.io/api/image/3.0/example/reference/329817fc8a251a01c393f517d8a17d87-Whistlers_Mother",
id="https://iiif.io/api/cookbook/recipe/0006-text-language/canvas/p1")
canvas.items[0].id = "https://iiif.io/api/cookbook/recipe/0006-text-language/page/p1/1"
canvas.items[0].items[0].id = "https://iiif.io/api/cookbook/recipe/0006-text-language/annotation/p0001-image"

print(manifest.json(indent=2))
--8<-- "docs/recipes/scripts/0006-text-language-method1.py"
```
26 changes: 6 additions & 20 deletions docs/recipes/0007-string-formats.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
# Embedding HTML in descriptive properties
### Recipe: [https://iiif.io/api/cookbook/recipe/0007-string-formats/](https://iiif.io/api/cookbook/recipe/0007-string-formats/)
### JSON-LD: [https://iiif.io/api/cookbook/recipe/0007-string-formats/manifest.json](https://iiif.io/api/cookbook/recipe/0007-string-formats/manifest.json)
| | **Cookbook URLs** |
|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| **Recipe:** | [https://iiif.io/api/cookbook/recipe/0007-string-formats/](https://iiif.io/api/cookbook/recipe/0007-string-formats/) |
| **JSON-LD:** | [https://iiif.io/api/cookbook/recipe/0007-string-formats/manifest.json](https://iiif.io/api/cookbook/recipe/0007-string-formats/manifest.json) |

## Method 1 - Building the object directly and making use of the AutoLang config
### Method 1 - Building the object directly and making use of the AutoLang config
```python
from iiif_prezi3 import Manifest, KeyValueString, config

config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"

manifest = Manifest(id="https://iiif.io/api/cookbook/recipe/0007-string-formats/manifest.json",
label="Picture of Göttingen taken during the 2019 IIIF Conference",
summary="<p>Picture taken by the <a href=\"https://github.com/glenrobson\">IIIF Technical Coordinator</a></p>",
rights="http://creativecommons.org/licenses/by-sa/3.0/",
requiredStatement=KeyValueString(label="Attribution",
value="<span>Glen Robson, IIIF Technical Coordinator. <a href=\"https://creativecommons.org/licenses/by-sa/3.0\">CC BY-SA 3.0</a> <img src=\"https://licensebuttons.net/l/by-sa/3.0/88x31.png\"/></span>"),
metadata=[KeyValueString(label="Author", value={"none": ["<span><a href='https://github.com/glenrobson'>Glen Robson</a></span>"]})])
canvas = manifest.make_canvas_from_iiif(url="https://iiif.io/api/image/3.0/example/reference/918ecd18c2592080851777620de9bcb5-gottingen",
id="https://iiif.io/api/cookbook/recipe/0007-string-formats/canvas/p1")
canvas.items[0].id = "https://iiif.io/api/cookbook/recipe/0007-string-formats/page/p1/1"
canvas.items[0].items[0].id = "https://iiif.io/api/cookbook/recipe/0007-string-formats/annotation/p0001-image"

print(manifest.json(indent=2))
--8<-- "docs/recipes/scripts/0007-string-formats-method1.py"
```
Loading