Favourites: some fixes to rendering the title
This commit is contained in:
parent
58be465329
commit
d3895800f3
5 changed files with 44 additions and 9 deletions
|
@ -29,7 +29,8 @@
|
||||||
"natural=stone"
|
"natural=stone"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"climbing="
|
"climbing=",
|
||||||
|
"sport!=climbing"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import Script from "./Script"
|
import Script from "./Script"
|
||||||
import { LayerConfigJson } from "../src/Models/ThemeConfig/Json/LayerConfigJson"
|
import { LayerConfigJson } from "../src/Models/ThemeConfig/Json/LayerConfigJson"
|
||||||
import { readFileSync, writeFileSync } from "fs"
|
import { existsSync, readFileSync, writeFileSync } from "fs"
|
||||||
import { AllSharedLayers } from "../src/Customizations/AllSharedLayers"
|
import { AllSharedLayers } from "../src/Customizations/AllSharedLayers"
|
||||||
import { AllKnownLayoutsLazy } from "../src/Customizations/AllKnownLayouts"
|
import { AllKnownLayoutsLazy } from "../src/Customizations/AllKnownLayouts"
|
||||||
import { Utils } from "../src/Utils"
|
import { Utils } from "../src/Utils"
|
||||||
|
@ -47,7 +47,6 @@ export class GenerateFavouritesLayer extends Script {
|
||||||
const bTag = TagUtils.Tag(b.if)
|
const bTag = TagUtils.Tag(b.if)
|
||||||
const aPop = TagUtils.GetPopularity(aTag)
|
const aPop = TagUtils.GetPopularity(aTag)
|
||||||
const bPop = TagUtils.GetPopularity(bTag)
|
const bPop = TagUtils.GetPopularity(bTag)
|
||||||
console.log("Comparing", a.if, "with", b.if, { aPop, bPop })
|
|
||||||
return aPop - bPop
|
return aPop - bPop
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -282,7 +281,14 @@ export class GenerateFavouritesLayer extends Script {
|
||||||
this.addTagRenderings(proto)
|
this.addTagRenderings(proto)
|
||||||
this.addTitle(proto)
|
this.addTitle(proto)
|
||||||
this.addTitleIcons(proto)
|
this.addTitleIcons(proto)
|
||||||
writeFileSync("./assets/layers/favourite/favourite.json", JSON.stringify(proto, null, " "))
|
const targetContent = JSON.stringify(proto, null, " ")
|
||||||
|
const path = "./assets/layers/favourite/favourite.json"
|
||||||
|
if (existsSync(path)) {
|
||||||
|
if (readFileSync(path, "utf8") === targetContent) {
|
||||||
|
return // No need to actually write the file, it is identical
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeFileSync(path, targetContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
private readLayer(path: string): LayerConfigJson {
|
private readLayer(path: string): LayerConfigJson {
|
||||||
|
|
|
@ -12,6 +12,9 @@ export class RegexTag extends TagsFilter {
|
||||||
super()
|
super()
|
||||||
this.key = key
|
this.key = key
|
||||||
this.value = value
|
this.value = value
|
||||||
|
if (this.value instanceof RegExp && ("" + this.value).startsWith("^(^(")) {
|
||||||
|
throw "Detected a duplicate start marker ^(^( in a regextag:" + this.value
|
||||||
|
}
|
||||||
this.invert = invert
|
this.invert = invert
|
||||||
this.matchesEmpty = RegexTag.doesMatch("", this.value)
|
this.matchesEmpty = RegexTag.doesMatch("", this.value)
|
||||||
}
|
}
|
||||||
|
@ -42,11 +45,21 @@ export class RegexTag extends TagsFilter {
|
||||||
return possibleRegex.test(fromTag)
|
return possibleRegex.test(fromTag)
|
||||||
}
|
}
|
||||||
|
|
||||||
private static source(r: string | RegExp) {
|
private static source(r: string | RegExp, includeStartMarker: boolean = true) {
|
||||||
if (typeof r === "string") {
|
if (typeof r === "string") {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
return r.source
|
if (r === undefined) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
const src = r.source
|
||||||
|
if (includeStartMarker) {
|
||||||
|
return src
|
||||||
|
}
|
||||||
|
if (src.startsWith("^(") && src.endsWith(")$")) {
|
||||||
|
return src.substring(2, src.length - 2)
|
||||||
|
}
|
||||||
|
return src
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,8 +96,22 @@ export class RegexTag extends TagsFilter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* import { TagUtils } from "./TagUtils";
|
||||||
|
*
|
||||||
|
* const t = TagUtils.Tag("a~b")
|
||||||
|
* t.asJson() // => "a~b"
|
||||||
|
*
|
||||||
|
* const t = TagUtils.Tag("a=")
|
||||||
|
* t.asJson() // => "a="
|
||||||
|
*/
|
||||||
asJson(): TagConfigJson {
|
asJson(): TagConfigJson {
|
||||||
return this.asHumanString()
|
const v = RegexTag.source(this.value, false)
|
||||||
|
if (typeof this.key === "string") {
|
||||||
|
const oper = typeof this.value === "string" ? "=" : "~"
|
||||||
|
return `${this.key}${this.invert ? "!" : ""}${oper}${v}`
|
||||||
|
}
|
||||||
|
return `${this.key.source}${this.invert ? "!" : ""}~~${v}`
|
||||||
}
|
}
|
||||||
|
|
||||||
isUsableAsAnswer(): boolean {
|
isUsableAsAnswer(): boolean {
|
||||||
|
|
|
@ -871,10 +871,10 @@ export class TagUtils {
|
||||||
|
|
||||||
public static GetPopularity(tag: TagsFilter): number | undefined {
|
public static GetPopularity(tag: TagsFilter): number | undefined {
|
||||||
if (tag instanceof And) {
|
if (tag instanceof And) {
|
||||||
return Math.min(...Utils.NoNull(tag.and.map((t) => TagUtils.GetPopularity(t))))
|
return Math.min(...Utils.NoNull(tag.and.map((t) => TagUtils.GetPopularity(t)))) - 1
|
||||||
}
|
}
|
||||||
if (tag instanceof Or) {
|
if (tag instanceof Or) {
|
||||||
return Math.max(...Utils.NoNull(tag.or.map((t) => TagUtils.GetPopularity(t))))
|
return Math.max(...Utils.NoNull(tag.or.map((t) => TagUtils.GetPopularity(t)))) + 1
|
||||||
}
|
}
|
||||||
if (tag instanceof Tag) {
|
if (tag instanceof Tag) {
|
||||||
return TagUtils.GetCount(tag.key, tag.value)
|
return TagUtils.GetCount(tag.key, tag.value)
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
onDestroy(
|
onDestroy(
|
||||||
tags.addCallbackAndRun((tags) => {
|
tags.addCallbackAndRun((tags) => {
|
||||||
_tags = tags
|
_tags = tags
|
||||||
|
console.log("Getting render value for", _tags,config)
|
||||||
trs = Utils.NoNull(config?.GetRenderValues(_tags))
|
trs = Utils.NoNull(config?.GetRenderValues(_tags))
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue