Skip to content

Commit

Permalink
update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mfenner committed Jan 8, 2025
1 parent 2000beb commit 7a1b055
Show file tree
Hide file tree
Showing 4 changed files with 1,044 additions and 982 deletions.
18 changes: 13 additions & 5 deletions commonmeta/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,16 +1092,24 @@ def name_to_fos(name: str) -> Optional[dict]:
return {"subject": subject}


def encode_doi(prefix):
def encode_doi(prefix, number: Optional[int]= None, checksum: bool = True) -> str:
"""Generate a DOI using the DOI prefix and a random base32 suffix"""
suffix = base32.generate(length=10, split_every=5, checksum=True)
if isinstance(number, int):
suffix = base32.encode(number, split_every=5, checksum=checksum)
else:
suffix = base32.generate(length=10, split_every=5, checksum=True)
return f"https://doi.org/{prefix}/{suffix}"


def decode_doi(doi: str) -> int:
def decode_doi(doi: str, checksum: bool = True) -> int:
"""Decode a DOI to a number"""
suffix = doi.split("/", maxsplit=5)[-1]
return base32.decode(suffix)
try:
suffix = doi.split("/", maxsplit=5)[-1]
if checksum:
return base32.decode(suffix, checksum=True)
return base32.decode(suffix)
except ValueError:
return 0


def from_curie(id: Optional[str]) -> Optional[str]:
Expand Down
4 changes: 2 additions & 2 deletions docs/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ website:
contents: "writers/*.ipynb"
- cli.qmd
page-footer:
left: "Copyright ©2023-2024 Front Matter."
left: "Copyright ©2023-2025 Front Matter."
right:
- icon: envelope
href: mailto:[email protected]
- icon: mastodon
href: https://rogue-scholar.social/@admin
href: https://indieweb.social/@commonmeta

format:
html:
Expand Down
Loading

0 comments on commit 7a1b055

Please sign in to comment.