Welcome to mirror list, hosted at ThFree Co, Russian Federation.

title.js « utils « repository « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9c4b334a1cead6614b286a57260e6b7d1fa58d22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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(' · ');
  }
}