Changes for page Export To Markdown
Last modified by Tobias Wintrich on 2026/03/27 13:39
From 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
To 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
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -1,60 +1,62 @@ 1 1 {{groovy}} 2 -import org.xwiki.model.reference.EntityReferenceSerializer 2 +import org.xwiki.model.reference.* 3 +import org.xwiki.model.EntityType 3 3 import java.io.File 4 4 5 -if (request. get('confirm')== '1') {6 +if (request.confirm == '1') { 6 6 7 7 // Zielverzeichnis 8 8 def exportDir = new File("/usr/local/xwiki/data/md-export") 9 9 exportDir.mkdirs() 10 10 11 - // Serializer für Ordnerstruktur 12 + // Serializer für saubere Ordnerstruktur 12 12 def pathSerializer = services.component.getInstance( 13 - EntityReferenceSerializer.TYPE_STRING, "fspath"14 + EntityReferenceSerializer.TYPE_STRING, 'fspath' 14 14 ) 15 15 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" 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 + """ 20 20 21 - def results = services.query.xwql(query).execute()24 + services.query.xwql(query).execute().each { fullName -> 22 22 23 - for(fullNamein results) {26 + println "* Exporting ${fullName}..." 24 24 25 - println("* Exporting " + fullName) 26 - 27 27 def doc = xwiki.getDocument(fullName) 28 28 29 29 if (doc.isHidden()) { 30 - continue31 + return 31 31 } 32 32 33 - // Markdown erzeugen34 - def markdown = services.rendering.render(doc.getXDOM(), "markdown/1.2")34 + // Markdown rendern 35 + def markdown = services.rendering.render(doc.getXDOM(), 'markdown/1.2') 35 35 36 - // Dateipfaderzeugen37 + // Verzeichnisstruktur erzeugen 37 37 def relativePath = pathSerializer.serialize(doc.documentReference) 38 38 def outputFile = new File(exportDir, relativePath + ".md") 39 39 40 40 outputFile.parentFile.mkdirs() 41 - outputFile. write(markdown, "UTF-8")42 + outputFile.text = markdown 42 42 43 - println (" -> Saved page to" +outputFile)44 + println " -> Saved page to ${outputFile}" 44 44 45 45 // Anhänge exportieren 46 - for (attachmentin doc.getAttachmentList()){47 + doc.attachmentList.each { attachment -> 47 47 48 - def attachmentFile = new File(outputFile.parentFile, attachment.getFilename()) 49 + def attachmentDir = outputFile.parentFile 50 + def attachmentFile = new File(attachmentDir, attachment.filename) 49 49 50 50 attachmentFile.withOutputStream { os -> 51 - os << attachment. getContentInputStream()53 + os << attachment.contentInputStream 52 52 } 53 53 54 - println (" -> Exported attachment" +attachment.getFilename())56 + println " -> Exported attachment ${attachment.filename}" 55 55 } 56 56 } 57 57 } 58 58 59 -println ("[[Export starten>>||queryString='confirm=1']]")61 +println "[[Export starten>>||queryString='confirm=1']]" 60 60 {{/groovy}}