Provide defaults for footer params

Fixes #10.
This commit is contained in:
Florine W. Dekker 2021-04-15 23:37:33 +02:00
parent 47f6532171
commit 68b5d33f54
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
3 changed files with 34 additions and 33 deletions

View File

@ -24,11 +24,3 @@ $> npm run dev:server
# Build the template in `dist/` for deployment
$> npm run deploy
```
### Publishing
```shell script
# Log in to npm
$> npm login
# Push to npm
$> npm publish --access public
```

View File

@ -1,8 +1,8 @@
{
"name": "@fwdekker/template",
"version": "1.0.1",
"version": "1.0.2",
"description": "The base template for pages on fwdekker.com.",
"author": "Felix W. Dekker (https://fwdekker.com)",
"author": "Felix W. Dekker",
"license": "MIT",
"homepage": "https://git.fwdekker.com/FWDekker/fwdekker-template",
"repository": {
@ -21,8 +21,7 @@
"clean": "grunt clean",
"dev": "grunt dev",
"dev:server": "grunt dev:server",
"deploy": "grunt deploy",
"prepare": "grunt clean deploy"
"deploy": "grunt deploy"
},
"dependencies": {
"milligram": "^1.4.1",

View File

@ -125,33 +125,43 @@ const header = function ({title, description}) {
/**
* Creates a footer element with the given data.
*
* @param [author] {string|undefined} the author
* @param [authorURL] {string|undefined} the URL to link the author's name to
* @param [license] {string|undefined} the type of license
* @param [licenseURL] {string|undefined} the URL to the license file
* @param [vcs] {string|undefined} the type of version control
* @param [vcsURL] {string|undefined} the URL to the repository
* @param [version] {string|undefined} the page version
* @param [privacyPolicyURL] {string|null|undefined} the URL to the privacy policy, or `null` if there should be no
* privacy policy, or `undefined` if the default privacy policy should be used
* Setting an argument to `undefined` or not giving that argument will cause the default value to be used. Setting an
* argument to `null` will result in a footer without the corresponding element.
*
* @param [author] {string|null|undefined} the author
* @param [authorURL] {string|null|undefined} the URL to link the author's name to
* @param [license] {string|null|undefined} the type of license
* @param [licenseURL] {string|null|undefined} the URL to the license file
* @param [vcs] {string|null|undefined} the type of version control
* @param [vcsURL] {string|null|undefined} the URL to the repository
* @param [version] {string|null|undefined} the page version
* @param [privacyPolicyURL] {string|null|undefined} the URL to the privacy policy
* @returns {HTMLElement} a footer element
*/
const footer = function (
{
author, authorURL, license, licenseURL, vcs, vcsURL, version,
author = undefined,
authorURL = undefined,
license = undefined,
licenseURL = undefined,
vcs = undefined,
vcsURL = undefined,
version = undefined,
privacyPolicyURL = undefined
}) {
if (author === undefined) author = "F.W. Dekker";
if (authorURL === undefined) authorURL = "https://fwdekker.com/";
if (license === undefined) license = "MIT License";
if (licenseURL === undefined && vcsURL !== undefined) licenseURL = `${vcsURL}src/branch/master/LICENSE`;
if (vcs === undefined && vcsURL !== undefined) vcs = "git";
if (privacyPolicyURL === undefined) privacyPolicyURL = "https://fwdekker.com/privacy/";
return stringToHtml(
`<footer class="footer"><section class="container">` +
footerLink("Made by ", author, authorURL, ". ") +
footerLink("Licensed under the ", license, licenseURL, ". ") +
footerLink("Source code available on ", vcs, vcsURL, ". ") +
footerLink(
"Consider reading the ",
privacyPolicyURL === null ? undefined : "privacy policy",
privacyPolicyURL === undefined ? "https://fwdekker.com/privacy/" : privacyPolicyURL,
". "
) +
footerLink("Consider reading the ", privacyPolicyURL && "privacy policy", privacyPolicyURL, ". ") +
`<div style="float: right;">${version || ""}</div>` +
`</section></footer>`,
"footer");
@ -161,15 +171,15 @@ const footer = function (
* Constructs a link that is used in footers.
*
* @param prefix {string} the text to display before the text if the text is not undefined
* @param text {string|undefined} the text to display, or `undefined` if the returned element should be empty
* @param url {string|undefined} the URL to link the text to, or `undefined` if the text should not be a link
* @param text {string|null} the text to display, or `null` if the returned element should be empty
* @param url {string|null} the URL to link the text to, or `null` if the text should not be a link
* @param suffix {string} the text to display after the text if the text is not undefined
* @returns {string} a footer link element
*/
const footerLink = function (prefix, text, url, suffix) {
if (text === undefined) return "";
if (text === null) return "";
return `${prefix}${url !== undefined ? `<a href="${url}">${text}</a>` : text}${suffix}`;
return `${prefix}${url !== null ? `<a href="${url}">${text}</a>` : text}${suffix}`;
};