diff --git a/src/mmt-stex/src/info/kwarc/mmt/stex/Extensions/Frontend.scala b/src/mmt-stex/src/info/kwarc/mmt/stex/Extensions/Frontend.scala new file mode 100644 index 0000000000..9ed3b6eefd --- /dev/null +++ b/src/mmt-stex/src/info/kwarc/mmt/stex/Extensions/Frontend.scala @@ -0,0 +1,33 @@ +package info.kwarc.mmt.stex.Extensions + +import info.kwarc.mmt.api.archives.Archive +import info.kwarc.mmt.api.utils.JSONArray.toList +import info.kwarc.mmt.api.utils.{File, JSON, JSONArray, JSONObject, JSONString} +import info.kwarc.mmt.stex.STeXServer + +trait FrontendExtension { this : STeXServer => + def getFrontendElements = { + getArchives.collect({ + case a : Archive => + val file = a.root / "META-INF" / "archive.json" + if (file.exists()) { + parseJson(File.read(file),a) + } else Nil + }).flatten + } + private def parseJson(s:String,a:Archive) : List[JSONObject] = { + JSON.parse(s) match { + case arr : JSONArray => toList(arr).collect{case jo:JSONObject => doObj(jo,a)} + case o : JSONObject => List(doObj(o,a)) + case _ => Nil + } + } + private def doObj(j:JSONObject,a:Archive) : JSONObject = { + JSONObject((JSONString("archive"),JSONString(a.id)) :: (j.map.map { + case (k@JSONString("landing"|"notes"|"slides"|"file"),JSONString(v)) => + if (!v.endsWith(".tex")) (k,JSONString(v + ".tex")) else (k,JSONString(v)) + //case (JSONString("thumbnail"), v) => ??? + case o => o + })) + } +} diff --git a/src/mmt-stex/src/info/kwarc/mmt/stex/STeXServer.scala b/src/mmt-stex/src/info/kwarc/mmt/stex/STeXServer.scala index 0728758450..01168b8f4b 100644 --- a/src/mmt-stex/src/info/kwarc/mmt/stex/STeXServer.scala +++ b/src/mmt-stex/src/info/kwarc/mmt/stex/STeXServer.scala @@ -1,14 +1,14 @@ package info.kwarc.mmt.stex import info.kwarc.mmt.api._ -import info.kwarc.mmt.api.archives.{Archive, ArchiveLike, RedirectableDimension} +import info.kwarc.mmt.api.archives.{Archive, ArchiveLike, RedirectableDimension, source} import info.kwarc.mmt.api.frontend.Extension import info.kwarc.mmt.api.objects._ import info.kwarc.mmt.api.presentation.Presenter import info.kwarc.mmt.api.utils.time.Time -import info.kwarc.mmt.api.utils.{File, FilePath, JSON, JSONObject, JSONString, MMTSystem, XMLEscaping} +import info.kwarc.mmt.api.utils.{File, FilePath, JSON, JSONArray, JSONObject, JSONString, MMTSystem, XMLEscaping} import info.kwarc.mmt.api.web.{ServerExtension, ServerRequest, ServerResponse} -import info.kwarc.mmt.stex.Extensions.{Definienda, ExampleRelational, ExportExtension, NotationExtractor, OMDocHTML, OMDocSHTMLRules, SHTMLBrowser, SHTMLContentManagement, SHTMLDocumentServer, SymdocRelational} +import info.kwarc.mmt.stex.Extensions.{Definienda, ExampleRelational, ExportExtension, FrontendExtension, NotationExtractor, OMDocHTML, OMDocSHTMLRules, SHTMLBrowser, SHTMLContentManagement, SHTMLDocumentServer, SymdocRelational} import info.kwarc.mmt.stex.lsp.{MathHubServer, RemoteLSP, STeXLSPServer, SearchResultServer} import info.kwarc.mmt.stex.rules.MathStructureFeature import info.kwarc.mmt.stex.vollki.{FullsTeXGraph, JupyterBookArchive, VirtualArchive, VollKi} @@ -24,7 +24,7 @@ case class ErrorReturn(s : String) extends Throwable { } -class STeXServer extends ServerExtension("sTeX") with OMDocSHTMLRules with SHTMLDocumentServer with SHTMLBrowser with SHTMLContentManagement with OMDocHTML with ExportExtension { +class STeXServer extends ServerExtension("sTeX") with OMDocSHTMLRules with SHTMLDocumentServer with SHTMLBrowser with SHTMLContentManagement with OMDocHTML with ExportExtension with FrontendExtension { def ctrl = controller def getArchives = controller.backend.getStores.collect { case a : Archive if a.properties.get("format").contains("stex") => a @@ -102,6 +102,20 @@ class STeXServer extends ServerExtension("sTeX") with OMDocSHTMLRules with SHTML documentRequest(request) case Some("omdoc" | "omdocfrag" | "omdocuri") => omdocRequest(request) + case Some("docidx") => + ServerResponse.JsonResponse(JSONArray(getFrontendElements :_*)) + case Some("thumbnail") => + val fp = request.query.split("/").init.mkString("/") + controller.backend.getArchive(fp) match { + case Some(a) => + val f = a / source / (request.query.split("/").last + ".png") + if (f.exists()) { + ServerResponse.FileResponse(f) + } + else ServerResponse("Image file " + request.query + ".png not found", "text/plain") + case _ => + ServerResponse("Image file " + request.query + ".png not found", "text/plain") + } case Some(":sTeX") if request.query == "" => browserRequest(request) case Some("browser") =>