github.com/Theta-Dev/Talon@v0.0.0-20211018130634-ff179e19fa9a/ui/menu/src/util/talonData.ts (about) 1 import type {TalonData, TalonPage, TalonVersion} from "./types" 2 import {TalonVisibility} from "./types" 3 4 const talonData: TalonData = JSON.parse( 5 document.getElementById("talon-data").textContent 6 ) as TalonData 7 8 const isTalonData = (obj: TalonData) => 9 "root_path" in obj && 10 "current_page" in obj && 11 "current_version" in obj && 12 "versions" in obj && 13 "pages" in obj 14 15 const isTalonVersion = (obj: TalonVersion) => "date" in obj && "user" in obj 16 17 const rootPath = talonData.root_path 18 19 const currentVersion = talonData.versions[talonData.current_version] 20 const currentVersionId = talonData.current_version 21 22 const getCurrentPage = () => { 23 if (talonData.current_page) { 24 return talonData.pages[talonData.current_page] 25 } else { 26 return { 27 name: "#" + talonData.current_version, 28 path: "&v/" + talonData.current_version, 29 color: "#7935df", 30 visibility: TalonVisibility.HIDDEN, 31 image: undefined, 32 source: undefined, 33 } 34 } 35 } 36 37 const currentPage: TalonPage = getCurrentPage() 38 const currentPageId = talonData.current_page 39 40 const isPresent = isTalonData(talonData) && isTalonVersion(currentVersion) 41 42 const versions = talonData.versions 43 const pages = talonData.pages 44 45 export { 46 rootPath, 47 isPresent, 48 currentVersion, 49 currentVersionId, 50 currentPage, 51 currentPageId, 52 versions, 53 pages, 54 }