@@ -31,7 +31,7 @@ protected function _preparePostCollection()
31
31
32
32
/**
33
33
* Get archive month
34
- * @return string
34
+ * @return int
35
35
*/
36
36
public function getMonth ()
37
37
{
@@ -40,7 +40,7 @@ public function getMonth()
40
40
41
41
/**
42
42
* Get archive year
43
- * @return string
43
+ * @return int
44
44
*/
45
45
public function getYear ()
46
46
{
@@ -58,6 +58,9 @@ protected function _prepareLayout()
58
58
$ this ->_addBreadcrumbs ($ title , 'blog_search ' );
59
59
$ this ->pageConfig ->getTitle ()->set ($ title );
60
60
61
+ $ this ->pageConfig ->setKeywords ($ this ->replaceVars ($ this ->_getConfigValue ('meta_keywords ' )));
62
+ $ this ->pageConfig ->setDescription ($ this ->replaceVars ($ this ->_getConfigValue ('meta_description ' )));
63
+
61
64
if ($ this ->config ->getDisplayCanonicalTag (\Magefan \Blog \Model \Config::CANONICAL_PAGE_TYPE_ARCHIVE )) {
62
65
$ month = '' ;
63
66
if ($ this ->getMonth ()) {
@@ -79,7 +82,7 @@ protected function _prepareLayout()
79
82
['attributes ' => ['rel ' => 'canonical ' ]]
80
83
);
81
84
}
82
- $ this ->pageConfig ->setRobots (' NOINDEX,FOLLOW ' );
85
+ $ this ->pageConfig ->setRobots ($ this -> _getConfigValue ( ' robots ' ) );
83
86
84
87
$ pageMainTitle = $ this ->getLayout ()->getBlock ('page.main.title ' );
85
88
if ($ pageMainTitle ) {
@@ -97,19 +100,48 @@ protected function _prepareLayout()
97
100
*/
98
101
protected function _getTitle ()
99
102
{
100
- if ($ this ->getMonth ()) {
101
- $ time = strtotime ($ this ->getYear () . '- ' . $ this ->getMonth () . '-01 ' );
102
- return sprintf (
103
- __ ('Monthly Archives: %s %s ' ),
104
- __ (date ('F ' , $ time )),
105
- date ('Y ' , $ time )
106
- );
107
- } else {
108
- $ time = strtotime ($ this ->getYear () . '-01-01 ' );
109
- return sprintf (
110
- __ ('Yearly Archives: %s ' ),
111
- date ('Y ' , $ time )
112
- );
103
+ return (string )$ this ->replaceVars ($ this ->_getConfigValue ('meta_title ' ) ?: $ this ->_getConfigValue ('title ' ));
104
+ }
105
+
106
+
107
+ /**
108
+ * @param $param
109
+ * @return mixed
110
+ */
111
+ protected function _getConfigValue ($ param )
112
+ {
113
+ return $ this ->_scopeConfig ->getValue (
114
+ 'mfblog/archive/ ' .$ param ,
115
+ ScopeInterface::SCOPE_STORE
116
+ );
117
+ }
118
+
119
+ /**
120
+ * @param $content
121
+ * @return array|mixed|string|string[]
122
+ */
123
+ private function replaceVars ($ content )
124
+ {
125
+ if (!$ content ) {
126
+ return '' ;
127
+ }
128
+ $ vars = ['year ' , 'month ' ];
129
+ $ values = [];
130
+ foreach ($ vars as $ var ) {
131
+ $ schemaVar = '{{ ' . $ var . '}} ' ;
132
+ if ($ content && strpos ($ content , $ schemaVar ) !== false ) {
133
+ switch ($ var ) {
134
+ case 'year ' :
135
+ $ values [$ var ] = date ('Y ' , strtotime ($ this ->getYear () . '-01-01 ' ));
136
+ break ;
137
+ case 'month ' :
138
+ $ values [$ var ] = date ('F ' , strtotime ($ this ->getYear () . '- ' . $ this ->getMonth () . '-01 ' ));
139
+ break ;
140
+ }
141
+ $ content = str_replace ($ schemaVar , $ values [$ var ] ?? '' , $ content );
142
+ }
143
+
113
144
}
145
+ return $ content ;
114
146
}
115
147
}
0 commit comments