Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Script: Header Blogs #844

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
32 changes: 20 additions & 12 deletions src/scripts/header_blogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { keyToCss } from '../util/css_map.js';
import { dom } from '../util/dom.js';
import { buildStyle } from '../util/interface.js';
import { pageModifications } from '../util/mutations.js';
import { getPreferences } from '../util/preferences.js';
import { userBlogs } from '../util/user.js';

const styleElement = buildStyle(`
Expand All @@ -21,40 +22,47 @@ const styleElement = buildStyle(`
#xkit-header-blogs {
overflow: hidden;
flex: 1.5;
max-width: max-content;
}

#xkit-header-blogs-inner {
display: flex;
flex-wrap: wrap;
justify-content: right;
justify-content: space-evenly;

height: 26px;

column-gap: 12px;
margin: 0px 16px;
margin: 0px 12px;
}

header > ${keyToCss('menuRight')} > ${keyToCss('container')}:empty {
margin: 0 !important;
}
`);

const avatarElements = userBlogs.map(({ name, avatar, theme: { avatarShape } }) => {
const { url } = avatar[avatar.length - 1];
return dom('a', { href: `/blog/${name}`, title: name }, null, [
dom('img', { class: `xkit-header-avatar ${avatarShape}`, src: url })
]);
});

const headerBlogElement = dom('div', { id: 'xkit-header-blogs' }, null, [
dom('div', { id: 'xkit-header-blogs-inner' }, null, avatarElements)
]);
let headerBlogElement;

const processRightMenu = ([rightMenu]) => {
rightMenu.before(headerBlogElement);
};

export const main = async function () {
const { maxBlogs } = await getPreferences('header_blogs');

const avatarElements = userBlogs
.slice(0, Number.parseInt(maxBlogs, 10) || Infinity)
.map(({ name, avatar, theme: { avatarShape } }) => {
const { url } = avatar[avatar.length - 1];
return dom('a', { href: `/blog/${name}`, title: name }, null, [
dom('img', { class: `xkit-header-avatar ${avatarShape}`, src: url })
]);
});

headerBlogElement = dom('div', { id: 'xkit-header-blogs' }, null, [
dom('div', { id: 'xkit-header-blogs-inner' }, null, avatarElements)
]);

document.head.append(styleElement);
pageModifications.register(`header > ${keyToCss('menuRight')}`, processRightMenu);
};
Expand Down
9 changes: 8 additions & 1 deletion src/scripts/header_blogs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,12 @@
"color": "white",
"background_color": "#000000"
},
"relatedTerms": [ "Header Options" ]
"relatedTerms": [ "Header Options" ],
"preferences": {
"maxBlogs": {
"type": "text",
"label": "Maximum blogs",
"default": "100"
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure you can use flex-wrap: wrap; overflow: hidden; to simply fill the available space cleanly

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am! But I think many people like putting like 3-5 blogs up there even if they have many more. (Legacy XKit defaulted to 3.) I personally don't want all 20+ blogs my main has access to up there if I fullscreen on a big monitor.

}
}