debian-mirror-gitlab/app/assets/javascripts/repository/utils/title.js
2020-03-13 15:44:24 +05:30

26 lines
711 B
JavaScript

const DEFAULT_TITLE = '· GitLab';
export const setTitle = (pathMatch, ref, project) => {
if (!pathMatch) {
document.title = `${project} ${DEFAULT_TITLE}`;
return;
}
const path = pathMatch.replace(/^\//, '');
const isEmpty = path === '';
/* eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings */
document.title = `${isEmpty ? 'Files' : path} · ${ref} · ${project} ${DEFAULT_TITLE}`;
};
export function updateRefPortionOfTitle(sha, doc = document) {
const { title = '' } = doc;
const titleParts = title.split(' · ');
if (titleParts.length > 1) {
titleParts[1] = sha;
/* eslint-disable-next-line no-param-reassign */
doc.title = titleParts.join(' · ');
}
}