diff options
author | João Augusto Costa Branco Marado Torres <torres.dev@disroot.org> | 2025-08-05 18:50:37 +0100 |
---|---|---|
committer | João Augusto Costa Branco Marado Torres <torres.dev@disroot.org> | 2025-08-05 18:50:37 +0100 |
commit | 0af094770c4ebabc56ff761a8bd215bc397c0f7e (patch) | |
tree | a9ad669c8b84b4d13897732ed93ccfcbbeb2cb25 /src/components/templates/licenses/CC.astro | |
parent | 84eef3f848c4efa18985a776021a58720744523a (diff) |
refactor: reading page review
Signed-off-by: João Augusto Costa Branco Marado Torres <torres.dev@disroot.org>
Diffstat (limited to 'src/components/templates/licenses/CC.astro')
-rw-r--r-- | src/components/templates/licenses/CC.astro | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/src/components/templates/licenses/CC.astro b/src/components/templates/licenses/CC.astro new file mode 100644 index 0000000..2aea423 --- /dev/null +++ b/src/components/templates/licenses/CC.astro @@ -0,0 +1,153 @@ +--- +import type { ComponentProps } from "astro/types"; +import type CopyrightNotice from "@components/templates/CopyrightNotice.astro"; +import { listYearsWithRanges } from "@utils/datetime"; +interface Props extends ComponentProps<typeof CopyrightNotice> {} + +let { license, title, holders, years } = Astro.props; + +if (typeof license !== "string") throw new Error(); + +const publicdomain = license === "CC0"; +const sa = /SA/.test(license); +const nd = /ND/.test(license); +const nc = /NC/.test(license); +const licenseURL = `https://creativecommons.org/licenses/${ + license.slice(3).toLowerCase() +}/4.0/`; + +const firstYear = Math.min(...years); +const lastYears = years.sort((a, b) => a - b).slice(1); +--- + +<footer itemprop="copyrightNotice"> + { + publicdomain ? ( + <p> + <small> + <a href={Astro.url}>{title}</a> by { + holders.map(({ name, url }) => { + if (name === undefined) return undefined; + + const website = url?.[0]; + + return ( + <span + itemprop="copyrightHolder" + itemscope + itemtype="https://schema.org/Person" + >{ + website !== undefined ? ( + <a + itemprop="url" + rel="author external noreferrer" + target="_blank" + href={website} + content={website} + ><span itemprop="name">{name}</span></a> + ) : <span itemprop="name">{name}</span> + }</span> + ); + }) + } is marked <a + itemprop="license" + rel="license noreferrer" + target="_blank" + href="https://creativecommons.org/publicdomain/zero/1.0/" + content="https://creativecommons.org/publicdomain/zero/1.0/" + >CC0 1.0</a> + <img + alt="" + src="https://mirrors.creativecommons.org/presskit/icons/cc.svg" + style="max-width: 1em; max-height: 1em; margin-left: 0.2em" + > + <img + alt="" + src="https://mirrors.creativecommons.org/presskit/icons/zero.svg" + style="max-width: 1em; max-height: 1em; margin-left: 0.2em" + > + </small> + </p> + ) : ( + <p> + <small> + <a href={Astro.url}>{title}</a> © <span itemprop="copyrightYear">{ + firstYear + }</span>, { + listYearsWithRanges(lastYears, { + list: { type: "unit", style: "narrow" }, + locale: "en", + }).replace(/^\d+/, "") + } by { + holders.map(({ name, url }) => { + if (name === undefined) return undefined; + + const website = url?.[0]; + + return ( + <span + itemprop="copyrightHolder" + itemscope + itemtype="https://schema.org/Person" + >{ + website !== undefined ? ( + <a + itemprop="url" + rel="author external noreferrer" + target="_blank" + href={website} + content={website} + ><span itemprop="name">{name}</span></a> + ) : <span itemprop="name">{name}</span> + }</span> + ); + }) + } is licensed under <a + itemprop="license" + rel="license noreferrer" + target="_blank" + href={licenseURL} + content={licenseURL} + >{license.replace("CC-", "CC ")} 4.0</a> + <img + alt="" + src="https://mirrors.creativecommons.org/presskit/icons/cc.svg" + style="max-width: 1em; max-height: 1em; margin-left: 0.2em" + > + <img + alt="" + src="https://mirrors.creativecommons.org/presskit/icons/by.svg" + style="max-width: 1em; max-height: 1em; margin-left: 0.2em" + > + { + nc && ( + <img + alt="" + src="https://mirrors.creativecommons.org/presskit/icons/nc.svg" + style="max-width: 1em; max-height: 1em; margin-left: 0.2em" + > + ) + } + { + sa && ( + <>{" "}<img + alt="" + src="https://mirrors.creativecommons.org/presskit/icons/sa.svg" + style="max-width: 1em; max-height: 1em; margin-left: 0.2em" + ></> + ) + } + { + nd && ( + <>{" "}<img + alt="" + src="https://mirrors.creativecommons.org/presskit/icons/nd.svg" + style="max-width: 1em; max-height: 1em; margin-left: 0.2em" + ></> + ) + } + </small> + </p> + ) + } +</footer> |