Answer the question
In order to leave comments, you need to log in
How to make the code when fetching headers more correctly?
Hello everyone, maybe someone has already had a similar one and will tell you how it is easier to implement everything.
I have a search on my site that has additional settings, such as take into account the user, section, etc.
Since these pages are in fact different, it would be foolish to prohibit search engines from indexing them, so I want to create unique titles for them.
There are GET requests
1. SEARCH - search word
2. CATALOG - document section
3. USER - document user
It was decided to make a certain key from get requests by which to select the title from the language file
This is how I create the key
function getPageTitleKey(request) {
return o = ["catalog", "user", "search"].filter(e => Object.keys(request).includes(e)), o.join(".")
}
//ru.js
//....
titles: {
"catalog": {
name: "CATALOG ...."
},
"search": {
name: "SEARCH ....."
},
"user": {
name: ".... USER"
},
"catalog.search": {
name: "SEARCH CATALOG ......"
},
"catalog.user": {
name: "CATALOG от пользователя USER"
},
"user.search": {
name: "SEARCH ..... добавленные пользователем USER"
},
"catalog.user.search": {
name: "SEARCH CATALOG от пользователя USER"
}
}
//....
switch(page_title_key) {
case "search": return isNameSearch(request)
case "catalog": return isNameCatalog(request)
case "catalog.user": return isNameCatalogUser(request)
//....
}
request.titles = function(e, key) {
return lang[key].name.replace("USER" e.user)
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question