Skip to content

Commit

Permalink
ref(social): Automatically set spacing
Browse files Browse the repository at this point in the history
Use map for socials
Automatically set spacing for each element to keep text always aligned
  • Loading branch information
coolapso committed Jun 7, 2024
1 parent 922e4ba commit 2cc0cc8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
13 changes: 6 additions & 7 deletions exampleSite/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
48 changes: 29 additions & 19 deletions layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -280,7 +290,7 @@

all = [
whois,
social,
social(),
work,
education,
skills,
Expand Down Expand Up @@ -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 }}
Expand Down

0 comments on commit 2cc0cc8

Please sign in to comment.