Skip to content

Commit

Permalink
refactor: extract parseCollection method
Browse files Browse the repository at this point in the history
  • Loading branch information
YakovL committed Jun 29, 2023
1 parent 3245677 commit 90fbf07
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions ExtensionsExplorerPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,28 @@ config.macros.extensionsExplorer = {
const textPathMatch = /\/(\w+)\.(js|txt)$/.exec(urlParts[0])
return textPathMatch ? textPathMatch[1] : undefined
},
parseCollection: function(text) {
/* expected format:
< additional info, like |Source|...| and other metadata >
//{{{
< extensions as JSON >
//}}}
*/
const match = /(\/\/{{{)\s+((?:.|\n)+)\s+(\/\/}}})$/.exec(text)
if(match) try {
return JSON.parse(match[2])
} catch (e) {
console.log(`problems with parsing ${centralSourcesListName}:`, e)
return null
}
},
//# use getAvailableRepositories to get lists of extensions
getAvailableExtensions: function() {
const listText = store.getTiddlerText(centralSourcesListName)
let availableExtensions
if(listText) {
/*
expected format:
... (here we can have some slices like |Source||)
//{{{
[ ... ]
//}}}
*/
const match = /(\/\/{{{)\s+((?:.|\n)+)\s+(\/\/}}})$/.exec(listText)
if(match) try {
availableExtensions = JSON.parse(match[2])
} catch (e) {
console.log(`problems with parsing ${centralSourcesListName}:`, e)
}
}
if(!availableExtensions) availableExtensions = this.defaultAvailableExtensions
const availableExtensions = this.parseCollection(listText)
|| this.defaultAvailableExtensions

//# move name normalizing to the reading method
// once we move the list of available extensions from hardcode
Expand Down

0 comments on commit 90fbf07

Please sign in to comment.