From 68b5d33f5434639353b36ad6a88f74cc33e8b532 Mon Sep 17 00:00:00 2001 From: "Felix W. Dekker" Date: Thu, 15 Apr 2021 23:37:33 +0200 Subject: [PATCH] Provide defaults for footer params Fixes #10. --- README.md | 8 ------- package.json | 7 +++--- src/main/js/main.js | 52 +++++++++++++++++++++++++++------------------ 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 75740f1..fb79cf9 100644 --- a/README.md +++ b/README.md @@ -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 -``` diff --git a/package.json b/package.json index 993251c..cd56b6c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/main/js/main.js b/src/main/js/main.js index fcb1876..752fe7c 100644 --- a/src/main/js/main.js +++ b/src/main/js/main.js @@ -84,7 +84,7 @@ const nav = function (highlightPath = "") { */ const unpackEntry = function (entry, path = "/", highlightPath = "") { const shouldHighlight = highlightPath.startsWith(`${path + entry.name}/`); - const isExternalLink = !entry.link.startsWith("https://fwdekker.com/") && entry.link !== "#"; + const isExternalLink = !entry.link.startsWith("https://fwdekker.com/") && entry.link !== "#"; const formattedName = (isExternalLink ? "⎋ " : "") + entry.name; if (entry.entries.length === 0) @@ -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"); @@ -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 ? `${text}` : text}${suffix}`; + return `${prefix}${url !== null ? `${text}` : text}${suffix}`; };