page-title-customization.ts 1006 B

1234567891011121314151617181920212223242526272829303132333435
  1. import { DevidedPagePath } from '@growi/core/dist/models';
  2. import { useAppTitle, useCustomTitleTemplate } from '~/states/global';
  3. /**
  4. * Generate whole title string for the specified title
  5. * @param props
  6. * @param title
  7. */
  8. export const useCustomTitle = (title: string): string => {
  9. const appTitle = useAppTitle();
  10. const customTitleTemplate = useCustomTitleTemplate();
  11. return customTitleTemplate
  12. .replace('{{sitename}}', appTitle)
  13. .replace('{{pagepath}}', title)
  14. .replace('{{pagename}}', title);
  15. };
  16. /**
  17. * Generate whole title string for the specified page path
  18. * @param props
  19. * @param pagePath
  20. */
  21. export const useCustomTitleForPage = (pagePath: string): string => {
  22. const appTitle = useAppTitle();
  23. const customTitleTemplate = useCustomTitleTemplate();
  24. const dPagePath = new DevidedPagePath(pagePath, true, true);
  25. return customTitleTemplate
  26. .replace('{{sitename}}', appTitle)
  27. .replace('{{pagepath}}', pagePath)
  28. .replace('{{pagename}}', dPagePath.latter);
  29. };