SSB Publish Markdown
Project description
SSB Publish Markdown
Features
- Write SSB articles using Quarto Markdown (qmd) files.
- Create SSB components using Python:
- Highchart
- Factbox
- Insert components in article using simple Markdown syntax.
Requirements
- A VSCode or Jupyter service in Dapla Lab.
- An SSB project.
Installation
poetry add ssb-pubmd
Latest development version:
poetry add ssb-pubmd@latest --source testpypi --allow-prereleases
Usage
poetry run ssb-pubmd create "My article title"
Follow further instructions in template file, and see the Reference Guide for details on creating components.
Contributing
Setup
-
Install uv (python and package manager):
curl -LsSf https://astral.sh/uv/install.sh | sh(See link for installation on Windows.)
-
Clone this repo.
git clone https://github.com/statisticsnorway/ssb-pubmd.git
Run tests
From the root folder (where pyproject.toml is), run:
uv run pytest
Testing the whole integration
- When you push changes to a branch, the package is published to Test PyPI by the release workflow.
- The test package can then be installed from a Dapla service and tested directly.
Steps
Use the following steps to test the most recently pushed change (to any branch):
-
Open a Jupyter service in Dapla Dev.
-
Open a Jupyter terminal and run the following commands:
ssb-project create my-project cd my-project poetry source add testpypi https://test.pypi.org/simple/ -p explicit poetry add "pandas<3" poetry add ssb-pubmd@latest --source testpypi --allow-prereleases poetry run ssb-pubmd create my-article
-
You can then continue testing in the same Dapla service. If you push new changes, you need to fetch these changes in the Dapla service with the following command:
poetry update ssb-pubmdNote that it takes about a minute (sometimes longer) for the PyPI Test package to be updated after pushing a change.
Architecture
Dependency graph:
graph LR
subgraph driving[Interface]
cli[cli]
end
subgraph core[Core]
project[create_project]
article[render_article]
docprocessor[Document processor]
docpublisher[Document publisher]
end
subgraph driven[Adapters]
cmsclient[Cms client]
storage[Storage]
end
cmsservice[Cms service]
cli --> project
cli --> article --> docpublisher
article --> docprocessor
docpublisher --> cmsclient
docpublisher --> storage
cmsclient --> cmsservice
classDef empty width:0px,height:0px;
Note: Cms Service refers to statisticsnorway/ssbno-app-pubmd.
General document flow:
- The user asks to render their notebook file through the command-line interface.
- The core method
render_articleuses the document processor to parse the file into a generalDocumentobject. - The
Documentobject is passed into the document publisher, which extracts the content and passes it to the CMS client. - The CMS client sends the content to the CMS service and returns the parsed response.
- The document processor stores the response, so that the id and path can be reused in future requests (to modify existing CMS content instead of creating new content).
Flow of components:
- Components are defined programmatically by the user in the notebook file.
- When the notebook is executed by the document processor, the
create_componentfunction (from__init__.py) stores the component data in a temporary storage file, which is then added to theDocumentobject. The temporary storage file is then deleted, to ensure sensitive data is not stored on disk. - The document publisher first extracts all the components from the
Documentobjects and sends these to the Cms Client. During this process, theDocumentobject is also modified so that components in the document tree are replaced with Cms references. - Finally the whole document is extracted (as html) and sent to the Cms client, with correct component references in the html.
Updates to Mimir content types
This package exposes a Python interface to mimir content types; see the source file interface/models.py. When mimir types change, the corresponding Python interface can be updated following these steps.
Adding a new field
There are two simple steps of adding an extra field to an exposed content type:
-
Decide how the extra field should be exposed to the user.
-
The exposed models are defined in interface/models.py.
-
Example of adding a required string field:
from pydantic import BaseModel class MyModel(BaseModel): extra_field: str
-
If the string field should be optional, a default value is given:
from pydantic import BaseModel class MyModel(BaseModel): extra_field: str | None = None another_field: str = "default-string"
-
See existing models for more examples. Remember to add a description of the field in the documentation string.
-
-
Add the extra field to the payload (that will be sent to the CMS).
-
The payload is created in the source file adapters/cms_client/mimir.py.
-
If we have added a field to the
Highchartmodel, we would add it to the payload in the method_create_highchart_payload. -
The payload must match the Mimir content type. For instance,
Highcharthas anxlabelfield which should be given asxAxisLabelin the payload.payload["xAxisTitle"] = data.xlabel
-
The easiest way to see how the payload should look is to use the Content Viewer in Content Studio, or the generated Enonic types.
-
License
Distributed under the terms of the MIT license, SSB Publish Markdown is free and open source software.
Issues
If you encounter any problems, please file an issue along with a detailed description.
Credits
This project was generated from Statistics Norway's SSB PyPI Template.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ssb_pubmd-0.2.1.tar.gz.
File metadata
- Download URL: ssb_pubmd-0.2.1.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57dafa86fe36ef4933195644a31e3b069f89284a5d786fb821ddf3b7f9ac1bd6
|
|
| MD5 |
bd58576284b54253a5f268a15d9f8c92
|
|
| BLAKE2b-256 |
f5ec50d745383ed5d634ec739e7a67ff74cd7b0faebc46bcc9fa3b19813ec840
|
Provenance
The following attestation bundles were made for ssb_pubmd-0.2.1.tar.gz:
Publisher:
release.yml on statisticsnorway/ssb-pubmd
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ssb_pubmd-0.2.1.tar.gz -
Subject digest:
57dafa86fe36ef4933195644a31e3b069f89284a5d786fb821ddf3b7f9ac1bd6 - Sigstore transparency entry: 1185820550
- Sigstore integration time:
-
Permalink:
statisticsnorway/ssb-pubmd@c48115aeee47503fe5cf052bcbb45ada75e96cc0 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/statisticsnorway
-
Access:
internal
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c48115aeee47503fe5cf052bcbb45ada75e96cc0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ssb_pubmd-0.2.1-py3-none-any.whl.
File metadata
- Download URL: ssb_pubmd-0.2.1-py3-none-any.whl
- Upload date:
- Size: 22.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41ad2f1ba9bcdd1e278162d1af799bda5bea59c9b2109dba9550294a923c97b5
|
|
| MD5 |
f8db27001c00421a1e5ff9eb40d4f8d6
|
|
| BLAKE2b-256 |
b7144fa2ffcc7548ed8d57c3eb4169434f1ac9847cf5984121e97008afe6d4ea
|
Provenance
The following attestation bundles were made for ssb_pubmd-0.2.1-py3-none-any.whl:
Publisher:
release.yml on statisticsnorway/ssb-pubmd
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ssb_pubmd-0.2.1-py3-none-any.whl -
Subject digest:
41ad2f1ba9bcdd1e278162d1af799bda5bea59c9b2109dba9550294a923c97b5 - Sigstore transparency entry: 1185820555
- Sigstore integration time:
-
Permalink:
statisticsnorway/ssb-pubmd@c48115aeee47503fe5cf052bcbb45ada75e96cc0 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/statisticsnorway
-
Access:
internal
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c48115aeee47503fe5cf052bcbb45ada75e96cc0 -
Trigger Event:
push
-
Statement type: