Concatenate the two most significant labels
This commit is contained in:
parent
cbd1b137cf
commit
fc9583ecd2
1 changed files with 39 additions and 5 deletions
|
|
@ -49,10 +49,16 @@ export class Application {
|
|||
const records = this.filteredRecords()
|
||||
records.sort(this.sortRecords)
|
||||
|
||||
// rec: for example www.google.com
|
||||
for (const rec of records) {
|
||||
// com.google (reverse and remove wwww)
|
||||
const labels = rec.labels().reverse().slice(0, -1)
|
||||
// It felt wrong when records for the base domain (e.g. google.com) was put in the top level domain (.com).
|
||||
// While technically correct, the first label (com) is grouped together with the second label (google).
|
||||
// Labels are counted reversely since the top domain is most significant.
|
||||
//
|
||||
// The `if` here is the exception for records that only has the two first labels. It would otherwise just
|
||||
// be an empty array of labels and thus discarded.
|
||||
let labels = rec.labels().reverse().slice(0, -1)
|
||||
if (rec.labels().length == 1)
|
||||
labels = rec.labels()
|
||||
|
||||
// Start each record from the top and iterate through all its labels
|
||||
// except the first one since that would be the actual record.
|
||||
|
|
@ -254,7 +260,18 @@ class Folder {
|
|||
return this.folderName.toLowerCase()
|
||||
}// }}}
|
||||
labels() {// {{{
|
||||
return this.name().split('.')
|
||||
let labels = this.name().split('.')
|
||||
|
||||
// It is very uncommon to see just the top level domain.
|
||||
// We're much more used to google.com than com and then google.
|
||||
// First level is therefore the two most significant labels concatenated.
|
||||
if (labels.length > 1) {
|
||||
labels.reverse()
|
||||
labels = [`${labels[1]}.${labels[0]}`].concat(labels.slice(2))
|
||||
labels.reverse()
|
||||
}
|
||||
|
||||
return labels
|
||||
}// }}}
|
||||
addRecord(rec) {// {{{
|
||||
this.records.push(rec)
|
||||
|
|
@ -401,7 +418,24 @@ class Record {
|
|||
return this.data.MatchSubdomain === 'true'
|
||||
}// }}}
|
||||
labels() {// {{{
|
||||
return this.name().split('.')
|
||||
let labels = this.name().split('.')
|
||||
|
||||
if (labels.length === 1) {
|
||||
labels = [labels[0], '_no', 'domain']
|
||||
}
|
||||
|
||||
// It is very uncommon to see just the top level domain.
|
||||
// We're much more used to google.com than com and then google.
|
||||
// First level is therefore the two most significant labels concatenated.
|
||||
if (labels.length > 1) {
|
||||
labels.reverse()
|
||||
labels = [`${labels[1]}.${labels[0]}`].concat(labels.slice(2))
|
||||
labels.reverse()
|
||||
} else {
|
||||
console.log(this, labels)
|
||||
}
|
||||
|
||||
return labels
|
||||
}// }}}
|
||||
|
||||
copy(el, text) {// {{{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue