1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.matchParamsPath = exports.getPageTitleInfo = exports.default = void 0;
|
9 |
|
10 | var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
11 |
|
12 | var _pathToRegexp = _interopRequireDefault(require("path-to-regexp"));
|
13 |
|
14 | var matchParamsPath = function matchParamsPath(pathname, breadcrumb, breadcrumbMap) {
|
15 |
|
16 |
|
17 | if (breadcrumbMap) {
|
18 | var pathKey = (0, _toConsumableArray2.default)(breadcrumbMap.keys()).find(function (key) {
|
19 | return (0, _pathToRegexp.default)(key).test(pathname);
|
20 | });
|
21 |
|
22 | if (pathKey) {
|
23 | return breadcrumbMap.get(pathKey);
|
24 | }
|
25 | }
|
26 |
|
27 |
|
28 |
|
29 | if (breadcrumb) {
|
30 | var _pathKey = Object.keys(breadcrumb).find(function (key) {
|
31 | return (0, _pathToRegexp.default)(key).test(pathname);
|
32 | });
|
33 |
|
34 | if (_pathKey) {
|
35 | return breadcrumb[_pathKey];
|
36 | }
|
37 | }
|
38 |
|
39 | return {
|
40 | path: ''
|
41 | };
|
42 | };
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | exports.matchParamsPath = matchParamsPath;
|
52 |
|
53 | var getPageTitleInfo = function getPageTitleInfo(props, ignoreTitle) {
|
54 | var _props$pathname = props.pathname,
|
55 | pathname = _props$pathname === void 0 ? '/' : _props$pathname,
|
56 | breadcrumb = props.breadcrumb,
|
57 | breadcrumbMap = props.breadcrumbMap,
|
58 | formatMessage = props.formatMessage,
|
59 | title = props.title,
|
60 | _props$menu = props.menu,
|
61 | menu = _props$menu === void 0 ? {
|
62 | locale: false
|
63 | } : _props$menu;
|
64 | var pageTitle = ignoreTitle ? '' : title || '';
|
65 | var currRouterData = matchParamsPath(pathname, breadcrumb, breadcrumbMap);
|
66 |
|
67 | if (!currRouterData) {
|
68 | return {
|
69 | title: pageTitle,
|
70 | id: '',
|
71 | pageName: pageTitle
|
72 | };
|
73 | }
|
74 |
|
75 | var pageName = currRouterData.name;
|
76 |
|
77 | if (menu.locale !== false && currRouterData.locale && formatMessage) {
|
78 | pageName = formatMessage({
|
79 | id: currRouterData.locale || '',
|
80 | defaultMessage: currRouterData.name
|
81 | });
|
82 | }
|
83 |
|
84 | if (!pageName) {
|
85 | return {
|
86 | title: pageTitle,
|
87 | id: currRouterData.locale || '',
|
88 | pageName: pageTitle
|
89 | };
|
90 | }
|
91 |
|
92 | if (ignoreTitle || !title) {
|
93 | return {
|
94 | title: pageName,
|
95 | id: currRouterData.locale || '',
|
96 | pageName: pageName
|
97 | };
|
98 | }
|
99 |
|
100 | return {
|
101 | title: "".concat(pageName, " - ").concat(title),
|
102 | id: currRouterData.locale || '',
|
103 | pageName: pageName
|
104 | };
|
105 | };
|
106 |
|
107 | exports.getPageTitleInfo = getPageTitleInfo;
|
108 |
|
109 | var getPageTitle = function getPageTitle(props, ignoreTitle) {
|
110 | return getPageTitleInfo(props, ignoreTitle).title;
|
111 | };
|
112 |
|
113 | var _default = getPageTitle;
|
114 | exports.default = _default; |
\ | No newline at end of file |