chapisha/helpers/pages.py
def create_colophon_xhtml(metadata: WorkMetadata) -> str:
    """
    Load the default `colophon.xhtml` file, and generate the required terms for the creative work. Return xhtml as a string.
    
    Parameters
    ----------
    metadata: WorkMetadata
        All the terms for updating the work, not all compulsory

    Returns
    -------
    str: xhtml response for `colophon.xhtml` as a str.
    """
    with open(DATA_PATH / "xhtml" / DEFAULT_COLOPHON_XHTML, "r+", encoding="utf-8") as xml_file:
        xml_txt = xml_file.read()
        # Set title
        xml_txt = xml_txt.replace("WORK_TITLE", metadata.title.upper())
        # Set author/s
        creator = metadata.creator
        if isinstance(creator, list):
            if len(creator) > 1:
                creator = " &amp; ".join([", ".join(creator[:-1]), creator[-1]])
            else:
                creator = creator[0]
        xml_txt = xml_txt.replace("AUTHOR, YEAR. RIGHTS.", F"{creator}, {metadata.isodate.year}. {metadata.rights}")
        # Set author url
        xml_url = ""
        if metadata.work_uri:
            xml_url = F'<p><a href="{metadata.work_uri}">{urlparse(metadata.work_uri).netloc}</a><br/></p>'
        xml_txt = xml_txt.replace('<p><a href="AUTHOR_URL">AUTHOR_URL</a><br/></p>', xml_url)
        # Set publication long-rights
        xml_rights = ""
        for p in formats.get_text_paragraphs(metadata.long_rights):
            xml_rights += F"\t\t\t<p>{p}</p>\n"
        xml_txt = xml_txt.replace("\t\t\t<p>PUBLICATION_RIGHTS</p>\n", xml_rights)
        # Set publisher and publisher url
        xml_pub = ""
        if metadata.publisher:
            xml_pub = F"<p><br/>Published by {metadata.publisher}.</p>"
        if metadata.publisher_uri:
            xml_pub = F'<p><br/>Published by <a href="{metadata.publisher_uri}">{metadata.publisher}</a>.</p>'
        xml_txt = xml_txt.replace("<p><br/>Published by PUBLISHER.</p>", xml_pub)
        # Set contributors
        xml_ctrb = ""
        for ctrb in [] if not metadata.contributor else metadata.contributor:
            # https://stackoverflow.com/a/38821619/295606
            if not ctrb.name: continue
            # If ctrb.year is None, then use work year
            if not ctrb.year:
                ctrb.year = metadata.isodate.year
            xml_ctrb += F"<p>{ctrb.role.capitalize()} contribution is copyright (c) {ctrb.name}, {ctrb.year}. {ctrb.terms}</p>"
        xml_txt = xml_txt.replace("<p>CONTRIBUTORS</p>", xml_ctrb)
    return xml_txt

    Load the default `colophon.xhtml` file, and generate the required terms for the creative work. Return xhtml as a string.
    
    Parameters
    ----------
    metadata: WorkMetadata
        All the terms for updating the work, not all compulsory

    Returns
    -------
    str: xhtml response for `colophon.xhtml` as a str.
    
Load the default `colophon.xhtml` file, and generate the required terms for the creative work. Return xhtml as a string.
Parameters

WorkMetadata
All the terms for updating the work, not all compulsory

Returns

xhtml response for `colophon.xhtml` as a str.
Load the default ` colophon . xhtml ` file and generate the required terms for the creative work . Return xhtml as a string . Parameters WorkMetadata All the terms for updating the work not all compulsory Returns xhtml response for ` colophon . xhtml ` as a str .
def create_colophon_xhtml(metadata: WorkMetadata) -> str:
    with open(DATA_PATH / "xhtml" / DEFAULT_COLOPHON_XHTML, "r+", encoding="utf-8") as xml_file:
        xml_txt = xml_file.read()
        xml_txt = xml_txt.replace("WORK_TITLE", metadata.title.upper())
        creator = metadata.creator
        if isinstance(creator, list):
            if len(creator) > 1:
                creator = " &amp; ".join([", ".join(creator[:-1]), creator[-1]])
            else:
                creator = creator[0]
        xml_txt = xml_txt.replace("AUTHOR, YEAR. RIGHTS.", F"{creator}, {metadata.isodate.year}. {metadata.rights}")
        xml_url = ""
        if metadata.work_uri:
            xml_url = F'<p><a href="{metadata.work_uri}">{urlparse(metadata.work_uri).netloc}</a><br/></p>'
        xml_txt = xml_txt.replace('<p><a href="AUTHOR_URL">AUTHOR_URL</a><br/></p>', xml_url)
        xml_rights = ""
        for p in formats.get_text_paragraphs(metadata.long_rights):
            xml_rights += F"\t\t\t<p>{p}</p>\n"
        xml_txt = xml_txt.replace("\t\t\t<p>PUBLICATION_RIGHTS</p>\n", xml_rights)
        xml_pub = ""
        if metadata.publisher:
            xml_pub = F"<p><br/>Published by {metadata.publisher}.</p>"
        if metadata.publisher_uri:
            xml_pub = F'<p><br/>Published by <a href="{metadata.publisher_uri}">{metadata.publisher}</a>.</p>'
        xml_txt = xml_txt.replace("<p><br/>Published by PUBLISHER.</p>", xml_pub)
        xml_ctrb = ""
        for ctrb in [] if not metadata.contributor else metadata.contributor:
            if not ctrb.name: continue
            if not ctrb.year:
                ctrb.year = metadata.isodate.year
            xml_ctrb += F"<p>{ctrb.role.capitalize()} contribution is copyright (c) {ctrb.name}, {ctrb.year}. {ctrb.terms}</p>"
        xml_txt = xml_txt.replace("<p>CONTRIBUTORS</p>", xml_ctrb)
    return xml_txt
def create_colophon_xhtml ( metadata : WorkMetadata ) -> str : with open ( DATA_PATH / "xhtml" / DEFAULT_COLOPHON_XHTML , "r+" , encoding = "utf-8" ) as xml_file : xml_txt = xml_file . read ( ) xml_txt = xml_txt . replace ( "WORK_TITLE" , metadata . title . upper ( ) ) creator = metadata . creator if isinstance ( creator , list ) : if len ( creator ) > 1 : creator = " &amp; " . join ( [ ", " . join ( creator [ : - 1 ] ) , creator [ - 1 ] ] ) else : creator = creator [ 0 ] xml_txt = xml_txt . replace ( "AUTHOR, YEAR. RIGHTS." , F"{creator}, {metadata.isodate.year}. {metadata.rights}" ) xml_url = "" if metadata . work_uri : xml_url = F'<p><a href="{metadata.work_uri}">{urlparse(metadata.work_uri).netloc}</a><br/></p>' xml_txt = xml_txt . replace ( '<p><a href="AUTHOR_URL">AUTHOR_URL</a><br/></p>' , xml_url ) xml_rights = "" for p in formats . get_text_paragraphs ( metadata . long_rights ) : xml_rights += F"\t\t\t<p>{p}</p>\n" xml_txt = xml_txt . replace ( "\t\t\t<p>PUBLICATION_RIGHTS</p>\n" , xml_rights ) xml_pub = "" if metadata . publisher : xml_pub = F"<p><br/>Published by {metadata.publisher}.</p>" if metadata . publisher_uri : xml_pub = F'<p><br/>Published by <a href="{metadata.publisher_uri}">{metadata.publisher}</a>.</p>' xml_txt = xml_txt . replace ( "<p><br/>Published by PUBLISHER.</p>" , xml_pub ) xml_ctrb = "" for ctrb in [ ] if not metadata . contributor else metadata . contributor : if not ctrb . name : continue if not ctrb . year : ctrb . year = metadata . isodate . year xml_ctrb += F"<p>{ctrb.role.capitalize()} contribution is copyright (c) {ctrb.name}, {ctrb.year}. {ctrb.terms}</p>" xml_txt = xml_txt . replace ( "<p>CONTRIBUTORS</p>" , xml_ctrb ) return xml_txt
Load the default `colophon.xhtml` file, and generate the required terms for the creative work.
Load the default ` colophon . xhtml ` file and generate the required terms for the creative work .
"""
    Load the default `colophon.xhtml` file, and generate the required terms for the creative work. Return xhtml as a string.
    
    Parameters
    ----------
    metadata: WorkMetadata
        All the terms for updating the work, not all compulsory

    Returns
    -------
    str: xhtml response for `colophon.xhtml` as a str.
    """ # Set title # Set author/s # Set author url # Set publication long-rights # Set publisher and publisher url # Set contributors # https://stackoverflow.com/a/38821619/295606 # If ctrb.year is None, then use work year
metadata
WorkMetadata