Changes for page Export To Markdown
Last modified by Tobias Wintrich on 2026/03/27 13:39
From version 5.1
edited by Tobias Wintrich
on 2026/03/27 13:28
on 2026/03/27 13:28
Change comment:
There is no comment for this version
To version 6.1
edited by Tobias Wintrich
on 2026/03/27 13:30
on 2026/03/27 13:30
Change comment:
There is no comment for this version
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -1,62 +1,60 @@ 1 1 {{groovy}} 2 -import org.xwiki.model.reference.* 3 -import org.xwiki.model.EntityType 2 +import org.xwiki.model.reference.EntityReferenceSerializer 4 4 import java.io.File 5 5 6 -if (request.confirm == '1') { 5 +if (request.get('confirm') == '1') { 7 7 8 8 // Zielverzeichnis 9 9 def exportDir = new File("/usr/local/xwiki/data/md-export") 10 10 exportDir.mkdirs() 11 11 12 - // Serializer für saubereOrdnerstruktur11 + // Serializer für Ordnerstruktur 13 13 def pathSerializer = services.component.getInstance( 14 - EntityReferenceSerializer.TYPE_STRING, 'fspath'13 + EntityReferenceSerializer.TYPE_STRING, "fspath" 15 15 ) 16 16 17 - // Nur veröffentlichte Dokumente (hidden = false) 18 - def query = """ 19 - select doc.fullName from Document doc 20 - where (doc.space like 'HowTos' or doc.space like 'HowTos.%') 21 - and doc.hidden = false 22 - """ 16 + // Query (einzeilig!) 17 + def query = "select doc.fullName from Document doc " + 18 + "where (doc.space like 'HowTos' or doc.space like 'HowTos.%') " + 19 + "and doc.hidden = false" 23 23 24 - services.query.xwql(query).execute() .each { fullName ->21 + def results = services.query.xwql(query).execute() 25 25 26 - println "* Exporting${fullName}..."23 + for (fullName in results) { 27 27 25 + println("* Exporting " + fullName) 26 + 28 28 def doc = xwiki.getDocument(fullName) 29 29 30 30 if (doc.isHidden()) { 31 - return30 + continue 32 32 } 33 33 34 - // Markdown re ndern35 - def markdown = services.rendering.render(doc.getXDOM(), 'markdown/1.2')33 + // Markdown erzeugen 34 + def markdown = services.rendering.render(doc.getXDOM(), "markdown/1.2") 36 36 37 - // Verzeichnisstrukturerzeugen36 + // Dateipfad erzeugen 38 38 def relativePath = pathSerializer.serialize(doc.documentReference) 39 39 def outputFile = new File(exportDir, relativePath + ".md") 40 40 41 41 outputFile.parentFile.mkdirs() 42 - outputFile.te xt =markdown41 + outputFile.write(markdown, "UTF-8") 43 43 44 - println " -> Saved page to${outputFile}"43 + println(" -> Saved page to " + outputFile) 45 45 46 46 // Anhänge exportieren 47 - doc.attachmentList.each { attachment->46 + for (attachment in doc.getAttachmentList()) { 48 48 49 - def attachmentDir = outputFile.parentFile 50 - def attachmentFile = new File(attachmentDir, attachment.filename) 48 + def attachmentFile = new File(outputFile.parentFile, attachment.getFilename()) 51 51 52 52 attachmentFile.withOutputStream { os -> 53 - os << attachment. contentInputStream51 + os << attachment.getContentInputStream() 54 54 } 55 55 56 - println " -> Exported attachment${attachment.filename}"54 + println(" -> Exported attachment " + attachment.getFilename()) 57 57 } 58 58 } 59 59 } 60 60 61 -println "[[Export starten>>||queryString='confirm=1']]"59 +println("[[Export starten>>||queryString='confirm=1']]") 62 62 {{/groovy}}