@daeryun/dr_components 1.3.48 → 1.3.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,10 +18,10 @@ import Image from 'next/image';
18
18
  import Arrow from '../../../asset/images/success_new/left.webp';
19
19
  import RightArrow from '../../../asset/images/success_new/right.webp';
20
20
  const Blog = ({ data, tel }) => {
21
- const { template, contentsList, h2List, fieldData, successData, referenceLinkList, newsLinkList, shortsLinkList, youtubeLinkList, initialData, nextPost, prevPost, faqElementMaxCountInContents } = data;
21
+ const { template, contentsList, h2List, fieldData, successData, referenceLinkList, newsLinkList, shortsLinkList, youtubeLinkList, initialData, nextPost, prevPost } = data;
22
22
  const { width } = useBrowser(true);
23
- const [isFaqActive, setIsFaqActive] = useState(false);
24
23
  const printRef = useRef(null);
24
+ const [faqElementMaxCountInContents, setFaqElementMaxCountInContents] = useState(0);
25
25
  const h1Title = template
26
26
  .map(temp => temp.tag === 'h1' && temp.tag_title)
27
27
  .filter(temp => temp !== false)
@@ -42,45 +42,60 @@ const Blog = ({ data, tel }) => {
42
42
  }
43
43
  }
44
44
  };
45
- const handleFaqItemType = (isFaqActive, faqElementMaxCountInContents) => {
46
- if (isFaqActive && faqElementMaxCountInContents === 0) {
47
- return 'https://schema.org/FAQPage';
48
- }
49
- if (isFaqActive && faqElementMaxCountInContents >= 2) {
45
+ const handleFaqItemType = () => {
46
+ // 작성자 FAQPage가 1개일 때만 루트 FAQPage를 제거한다.
47
+ if (faqElementMaxCountInContents === 1) {
50
48
  return undefined;
51
49
  }
52
50
  return 'https://schema.org/FAQPage';
53
51
  };
54
- const handleFaqItemScope = (isFaqActive, faqElementMaxCountInContents) => {
55
- if (isFaqActive && faqElementMaxCountInContents === 0) {
56
- return true;
57
- }
58
- if (isFaqActive && faqElementMaxCountInContents >= 2) {
52
+ const handleFaqItemScope = () => {
53
+ // 작성자 FAQPage가 1개일 때만 루트 FAQPage를 제거한다.
54
+ if (faqElementMaxCountInContents === 1) {
59
55
  return undefined;
60
56
  }
61
57
  return true;
62
58
  };
63
59
  const convertFaqItemType = (template) => {
64
- if (faqElementMaxCountInContents >= 2) {
65
- // faqElementMaxCountInContents가 두 개 이상일 경우, template 내부에 FAQPage itemtype을 지운다. FAQPage 중복 이슈로 인한 코드임
66
- template.description = template.description.replaceAll('<div itemscope="" itemtype="https://schema.org/FAQPage">', '<div>');
67
- return template;
60
+ // 작성자 FAQPage가 2개 이상이면 내부 FAQPage를 지우고 루트 FAQPage 1개만 유지한다.
61
+ if (faqElementMaxCountInContents) {
62
+ if (faqElementMaxCountInContents >= 2) {
63
+ const convertedDescription = template.description
64
+ .replaceAll('<div itemscope="" itemtype="https://schema.org/FAQPage">', '<div>')
65
+ .replaceAll('<div itemscope="" itemtype="https://schema.org/FAQPage">', '<div>');
66
+ return Object.assign(Object.assign({}, template), { description: convertedDescription });
67
+ }
68
68
  }
69
- return template;
69
+ return Object.assign({}, template);
70
70
  };
71
+ // template, h2List 순회
71
72
  useEffect(() => {
72
73
  if (template) {
73
- // 초기화
74
- setIsFaqActive(false);
75
- for (const data of template) {
76
- // console.log("faq 활성화: ", data['active_faq']);
77
- if (data['active_faq']) {
78
- setIsFaqActive(true);
74
+ template.forEach(data => {
75
+ if (data.description) {
76
+ data.faqCount =
77
+ data.description.split('FAQPage').length >= 2 ? data.description.split('FAQPage').length : 0;
78
+ setFaqElementMaxCountInContents(Math.max(...template.map(data => data.faqCount)));
79
79
  }
80
- }
80
+ else {
81
+ data.faqCount = 0;
82
+ }
83
+ });
84
+ }
85
+ if (h2List) {
86
+ h2List.forEach(data => {
87
+ if (data.description && template) {
88
+ data.faqCount =
89
+ data.description.split('FAQPage').length >= 2 ? data.description.split('FAQPage').length : 0;
90
+ setFaqElementMaxCountInContents(Math.max(...template.map(data => data.faqCount)));
91
+ }
92
+ else {
93
+ data.faqCount = 0;
94
+ }
95
+ });
81
96
  }
82
- }, [template]);
83
- return (<div itemScope={handleFaqItemScope(isFaqActive, faqElementMaxCountInContents)} itemType={handleFaqItemType(isFaqActive, faqElementMaxCountInContents)} ref={printRef}>
97
+ }, [template, h2List]);
98
+ return (<div itemScope={handleFaqItemScope()} itemType={handleFaqItemType()} ref={printRef}>
84
99
  <div id={'sub_contents'}>
85
100
  <div className="relative m-auto mb-[60px] w-[90%] max-w-screen-2xl max-xs:mb-[30px]">
86
101
  <div className={'m-auto mt-[100px] flex gap-[120px] lg:mt-[5em] ' +
@@ -121,7 +136,7 @@ const Blog = ({ data, tel }) => {
121
136
  {/*h3*/}
122
137
  {template
123
138
  .filter(t => t.parent === h2Template.idx)
124
- .map((h3Template, h3Index) => {
139
+ .map(h3Template => {
125
140
  const refer_is_use = h3Template.reference_is_use;
126
141
  const refer_length = referenceLinkList.length;
127
142
  const refer_content_length = referenceLinkList.filter(i => i.tag_idx === h3Template.idx).length;
@@ -129,7 +144,7 @@ const Blog = ({ data, tel }) => {
129
144
  const news_length = newsLinkList.length;
130
145
  const news_content_length = newsLinkList.filter(i => i.tag_idx === h3Template.idx).length;
131
146
  return (<Fragment key={'h3Contents_section_' + h3Template.idx}>
132
- <H3Contents h3Template={convertFaqItemType(h3Template)} faqCount={h3Template === null || h3Template === void 0 ? void 0 : h3Template.faqCount}/>
147
+ <H3Contents h3Template={convertFaqItemType(h3Template)} key={'h3영역' + h3Template.idx} faqCount={h3Template === null || h3Template === void 0 ? void 0 : h3Template.faqCount}/>
133
148
  {(refer_is_use &&
134
149
  refer_length > 0 &&
135
150
  refer_content_length > 0) ||
@@ -34,12 +34,11 @@ const Blog = ({ data, tel }: IBlogPageTypes) => {
34
34
  youtubeLinkList,
35
35
  initialData,
36
36
  nextPost,
37
- prevPost,
38
- faqElementMaxCountInContents
37
+ prevPost
39
38
  } = data;
40
39
  const { width } = useBrowser(true);
41
- const [isFaqActive, setIsFaqActive] = useState<boolean>(false);
42
40
  const printRef = useRef<HTMLDivElement>(null);
41
+ const [faqElementMaxCountInContents, setFaqElementMaxCountInContents] = useState<number>(0);
43
42
 
44
43
  const h1Title: string = template
45
44
  .map(temp => temp.tag === 'h1' && temp.tag_title)
@@ -63,24 +62,18 @@ const Blog = ({ data, tel }: IBlogPageTypes) => {
63
62
  }
64
63
  };
65
64
 
66
- const handleFaqItemType = (isFaqActive: boolean, faqElementMaxCountInContents?: number): string | undefined => {
67
- if (isFaqActive && faqElementMaxCountInContents === 0) {
68
- return 'https://schema.org/FAQPage';
69
- }
70
-
71
- if (isFaqActive && (faqElementMaxCountInContents as number) >= 2) {
65
+ const handleFaqItemType = (): string | undefined => {
66
+ // 작성자 FAQPage가 1개일 때만 루트 FAQPage를 제거한다.
67
+ if (faqElementMaxCountInContents === 1) {
72
68
  return undefined;
73
69
  }
74
70
 
75
71
  return 'https://schema.org/FAQPage';
76
72
  };
77
73
 
78
- const handleFaqItemScope = (isFaqActive: boolean, faqElementMaxCountInContents?: number): true | undefined => {
79
- if (isFaqActive && faqElementMaxCountInContents === 0) {
80
- return true;
81
- }
82
-
83
- if (isFaqActive && (faqElementMaxCountInContents as number) >= 2) {
74
+ const handleFaqItemScope = (): true | undefined => {
75
+ // 작성자 FAQPage가 1개일 때만 루트 FAQPage를 제거한다.
76
+ if (faqElementMaxCountInContents === 1) {
84
77
  return undefined;
85
78
  }
86
79
 
@@ -88,39 +81,52 @@ const Blog = ({ data, tel }: IBlogPageTypes) => {
88
81
  };
89
82
 
90
83
  const convertFaqItemType = (template: ISeoTemplateTypes): ISeoTemplateTypes => {
91
- if ((faqElementMaxCountInContents as number) >= 2) {
92
- // faqElementMaxCountInContents가 두 개 이상일 경우, template 내부에 FAQPage itemtype을 지운다. FAQPage 중복 이슈로 인한 코드임
93
- template.description = template.description.replaceAll(
94
- '&lt;div itemscope="" itemtype="https://schema.org/FAQPage"&gt;',
95
- '&lt;div&gt;'
96
- );
84
+ // 작성자 FAQPage가 2개 이상이면 내부 FAQPage를 지우고 루트 FAQPage 1개만 유지한다.
85
+ if (faqElementMaxCountInContents) {
86
+ if (faqElementMaxCountInContents >= 2) {
87
+ const convertedDescription = template.description
88
+ .replaceAll('&lt;div itemscope="" itemtype="https://schema.org/FAQPage"&gt;', '&lt;div&gt;')
89
+ .replaceAll('<div itemscope="" itemtype="https://schema.org/FAQPage">', '<div>');
97
90
 
98
- return template;
91
+ return {
92
+ ...template,
93
+ description: convertedDescription
94
+ };
95
+ }
99
96
  }
100
97
 
101
- return template;
98
+ return { ...template };
102
99
  };
103
100
 
101
+ // template, h2List 순회
104
102
  useEffect(() => {
105
103
  if (template) {
106
- // 초기화
107
- setIsFaqActive(false);
104
+ template.forEach(data => {
105
+ if (data.description) {
106
+ data.faqCount =
107
+ data.description.split('FAQPage').length >= 2 ? data.description.split('FAQPage').length : 0;
108
+ setFaqElementMaxCountInContents(Math.max(...template.map(data => data.faqCount as number)));
109
+ } else {
110
+ data.faqCount = 0;
111
+ }
112
+ });
113
+ }
108
114
 
109
- for (const data of template) {
110
- // console.log("faq 활성화: ", data['active_faq']);
111
- if (data['active_faq']) {
112
- setIsFaqActive(true);
115
+ if (h2List) {
116
+ h2List.forEach(data => {
117
+ if (data.description && template) {
118
+ data.faqCount =
119
+ data.description.split('FAQPage').length >= 2 ? data.description.split('FAQPage').length : 0;
120
+ setFaqElementMaxCountInContents(Math.max(...template.map(data => data.faqCount as number)));
121
+ } else {
122
+ data.faqCount = 0;
113
123
  }
114
- }
124
+ });
115
125
  }
116
- }, [template]);
126
+ }, [template, h2List]);
117
127
 
118
128
  return (
119
- <div
120
- itemScope={handleFaqItemScope(isFaqActive, faqElementMaxCountInContents as number)}
121
- itemType={handleFaqItemType(isFaqActive, faqElementMaxCountInContents as number)}
122
- ref={printRef}
123
- >
129
+ <div itemScope={handleFaqItemScope()} itemType={handleFaqItemType()} ref={printRef}>
124
130
  <div id={'sub_contents'}>
125
131
  <div className="relative m-auto mb-[60px] w-[90%] max-w-screen-2xl max-xs:mb-[30px]">
126
132
  <div
@@ -195,7 +201,7 @@ const Blog = ({ data, tel }: IBlogPageTypes) => {
195
201
  {/*h3*/}
196
202
  {template
197
203
  .filter(t => t.parent === h2Template.idx)
198
- .map((h3Template, h3Index) => {
204
+ .map(h3Template => {
199
205
  const refer_is_use = h3Template.reference_is_use;
200
206
  const refer_length = referenceLinkList.length;
201
207
  const refer_content_length = referenceLinkList.filter(
@@ -212,6 +218,7 @@ const Blog = ({ data, tel }: IBlogPageTypes) => {
212
218
  <Fragment key={'h3Contents_section_' + h3Template.idx}>
213
219
  <H3Contents
214
220
  h3Template={convertFaqItemType(h3Template)}
221
+ key={'h3영역' + h3Template.idx}
215
222
  faqCount={h3Template?.faqCount}
216
223
  />
217
224
  {(refer_is_use &&
@@ -110,7 +110,7 @@ export function categoryMenuName({ url }) {
110
110
  return { title: 'SNS', subTitle: '인스타그램', address: 'instagram' };
111
111
  }
112
112
  else if (url.includes('/blog')) {
113
- return { title: 'SNS', subTitle: '블로그', address: 'blog' };
113
+ return { title: '소식/자료', subTitle: '법률 블로그', address: 'blog' };
114
114
  }
115
115
  else if (url.includes('/common/disclaimer')) {
116
116
  return { title: '면책공고', subTitle: '면책공고', address: 'common/disclaimer' };
@@ -94,7 +94,7 @@ export function categoryMenuName({ url }: { url: string }): {
94
94
  } else if (url.includes('/instagram')) {
95
95
  return { title: 'SNS', subTitle: '인스타그램', address: 'instagram' };
96
96
  } else if (url.includes('/blog')) {
97
- return { title: 'SNS', subTitle: '블로그', address: 'blog' };
97
+ return { title: '소식/자료', subTitle: '법률 블로그', address: 'blog' };
98
98
  } else if (url.includes('/common/disclaimer')) {
99
99
  return { title: '면책공고', subTitle: '면책공고', address: 'common/disclaimer' };
100
100
  } else if (url.includes('/common/limited-liability')) {