summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/repository/utils/title.js
blob: 442f6c5d7419835b04f38e35327d6aa2ac66fdb4 (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/require-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(' · ');
  }
}