Skip to content

Commit

Permalink
merged devel
Browse files Browse the repository at this point in the history
  • Loading branch information
Jazzpirate committed Jun 19, 2023
2 parents 944db9f + 257148a commit 1ccd931
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
33 changes: 33 additions & 0 deletions src/mmt-stex/src/info/kwarc/mmt/stex/Extensions/Frontend.scala
Original file line number Diff line number Diff line change
@@ -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
}))
}
}
22 changes: 18 additions & 4 deletions src/mmt-stex/src/info/kwarc/mmt/stex/STeXServer.scala
Original file line number Diff line number Diff line change
@@ -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, STeXRelationals, SymdocRelational}
import info.kwarc.mmt.stex.Extensions.{Definienda, ExampleRelational, ExportExtension, FrontendExtension, NotationExtractor, OMDocHTML, OMDocSHTMLRules, SHTMLBrowser, SHTMLContentManagement, SHTMLDocumentServer, STeXRelationals, 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}
Expand All @@ -24,7 +24,7 @@ case class ErrorReturn(s : String) extends Throwable {
}


class STeXServer extends ServerExtension("sTeX") with OMDocSHTMLRules with SHTMLDocumentServer with SHTMLBrowser with OMDocHTML with ExportExtension {
class STeXServer extends ServerExtension("sTeX") with OMDocSHTMLRules with SHTMLDocumentServer with SHTMLBrowser 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
Expand Down Expand Up @@ -106,6 +106,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") =>
Expand Down

0 comments on commit 1ccd931

Please sign in to comment.