Modifications pour le document Export To Markdown
Modifié par Tobias Wintrich le 2026/03/27 13:39
Depuis la version 5.1
modifié par Tobias Wintrich
sur 2026/03/27 13:28
sur 2026/03/27 13:28
Commentaire de modification :
Il n'y a aucun commentaire pour cette version
À la version 4.1
modifié par Tobias Wintrich
sur 2026/03/27 13:23
sur 2026/03/27 13:23
Commentaire de modification :
Il n'y a aucun commentaire pour cette version
Résumé
-
Propriétés de la Page (1 modifications, 0 ajouts, 0 suppressions)
Détails
- Propriétés de la Page
-
- Contenu
-
... ... @@ -1,62 +1,33 @@ 1 1 {{groovy}} 2 2 import org.xwiki.model.reference.* 3 -import org.xwiki.model.EntityType 4 4 import java.io.File 5 5 6 6 if (request.confirm == '1') { 6 + // Festes Export-Verzeichnis 7 + def tmpDir = new File("/usr/local/xwiki/data/md-export") 8 + tmpDir.mkdirs() 7 7 8 - // Zielverzeichnis 9 - def exportDir = new File("/usr/local/xwiki/data/md-export") 10 - exportDir.mkdirs() 10 + services.query.xwql( 11 + "select distinct doc.fullName from Document doc " + 12 + "where doc.space like 'HowTos' or doc.space like 'HowTos.%'" 13 + ).execute().each() { 11 11 12 - // Serializer für saubere Ordnerstruktur 13 - def pathSerializer = services.component.getInstance( 14 - EntityReferenceSerializer.TYPE_STRING, 'fspath' 15 - ) 15 + print "* Converting ${it} to MD..." 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 - """ 17 + def itemDoc = xwiki.getDocument(it) 18 + def newContent = services.rendering.render(itemDoc.getXDOM(), 'markdown/1.2') 23 23 24 - services.query.xwql(query).execute().each { fullName -> 20 + def pathSerializer = services.component.getInstance( 21 + EntityReferenceSerializer.TYPE_STRING, 'fspath' 22 + ) 25 25 26 - println "* Exporting ${fullName}..." 27 - 28 - def doc = xwiki.getDocument(fullName) 29 - 30 - if (doc.isHidden()) { 31 - return 32 - } 33 - 34 - // Markdown rendern 35 - def markdown = services.rendering.render(doc.getXDOM(), 'markdown/1.2') 36 - 37 - // Verzeichnisstruktur erzeugen 38 - def relativePath = pathSerializer.serialize(doc.documentReference) 39 - def outputFile = new File(exportDir, relativePath + ".md") 40 - 24 + def outputFile = new File(tmpDir, pathSerializer.serialize(itemDoc.documentReference)) 41 41 outputFile.parentFile.mkdirs() 42 - outputFile.text = markdown26 + outputFile.text = newContent 43 43 44 - println " -> Saved page to ${outputFile}" 45 - 46 - // Anhänge exportieren 47 - doc.attachmentList.each { attachment -> 48 - 49 - def attachmentDir = outputFile.parentFile 50 - def attachmentFile = new File(attachmentDir, attachment.filename) 51 - 52 - attachmentFile.withOutputStream { os -> 53 - os << attachment.contentInputStream 54 - } 55 - 56 - println " -> Exported attachment ${attachment.filename}" 57 - } 28 + println "Saved in ${outputFile.toString()}" 58 58 } 59 59 } 60 60 61 -println "[[Export starten>>||queryString='confirm=1']]"32 +println "[[Export>>||queryString='confirm=1']]" 62 62 {{/groovy}}