From 2cc0cc87a89e02430a69a0c82f6a4f7c4d932b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Cola=C3=A7o?= Date: Fri, 7 Jun 2024 16:56:36 +0200 Subject: [PATCH] ref(social): Automatically set spacing Use map for socials Automatically set spacing for each element to keep text always aligned --- exampleSite/config.yml | 13 ++++++------ layouts/index.html | 48 +++++++++++++++++++++++++----------------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/exampleSite/config.yml b/exampleSite/config.yml index f73fc76..ab84343 100644 --- a/exampleSite/config.yml +++ b/exampleSite/config.yml @@ -38,19 +38,18 @@ params: # useLess: true # hideName: true details: - ## IF you want to keep them aligned just add spaces - name: "github" - url: " https://github.com" + url: "https://github.com" - name: "facebook" - url: " https://facebook.com" + url: "https://facebook.com" - name: "myspace" - url: " https://myspace.com" + url: "https://myspace.com" - name: "hi5" - url: " https://www.hi5.com" + url: "https://www.hi5.com" - name: "instagram" - url: " https://instagram.com" + url: "https://instagram.com" - name: "Another social" - url: " https://anothersocial.com" + url: "https://anothersocial.com" work: # settings: diff --git a/layouts/index.html b/layouts/index.html index d21d214..25dcb4a 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -96,13 +96,13 @@ } // Calculate the tabbing to keep commands and descriptions aligned in the help message - let longestKeyLength = Math.max(...Object.keys(commands).map(key => key.length)); - function padKey(key, length) { return key + ' '.repeat(length - key.length); } function commandsHelp() { + let longestKeyLength = Math.max(...Object.keys(commands).map(key => key.length)); + commandsHelp = "" for (let key in commands) { if (commands.hasOwnProperty(key)) { @@ -137,23 +137,33 @@ {{ end }} ]; - var social = [ - {{ if .Site.Params.social.settings.hideName }} - {{ with .Site.Params.social.details }} - {{ range . }} - '{{ .url }}', + function social() { + var hideName = false; + let sMap = { + {{ with .Site.Params.social.details }} + {{ range. }} + {{ .name }}: "{{ .url }}", + {{ end }} {{ end }} - '\r', - {{ end }} - {{ else }} - {{ with .Site.Params.social.details }} - {{ range . }} - '{{ .name }}: {{ .url }}', - {{ end }} - '\r', + }; + + {{ if .Site.Params.social.settings.hideName }} + hideName = true {{ end }} - {{ end }} - ]; + socialText = [] + for (let key in sMap) { + if (sMap.hasOwnProperty(key)) { + if (hideName) { + socialText.push(sMap[key]); + } else { + let longestKeyLength = Math.max(...Object.keys(sMap).map(key => key.length)); + socialText.push(`${padKey(key, longestKeyLength)}\t${sMap[key]}`) + }; + } + } + + return socialText + } var certifications = [ {{ with .Site.Params.certifications.details }} @@ -280,7 +290,7 @@ all = [ whois, - social, + social(), work, education, skills, @@ -313,7 +323,7 @@ {{ if .Site.Params.social.settings.useLess }} useLess = true; {{ end }} - echoArray(social); + echoArray(social()); break; case 'work': {{ if .Site.Params.work.settings.useLess }}