From 1a380405a35a9ff26595d05c7f1829386c31693f Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Tue, 19 Mar 2024 07:27:38 -0500 Subject: [PATCH] Improving table of contents management. --- src/MiniDocs/Markdown.class.st | 11 ++++---- src/MiniDocs/Pandoc.class.st | 5 ++-- src/MiniDocs/PubPubContent.class.st | 25 +++++++++++++++++- src/MiniDocs/PubPubWork.class.st | 40 ++++++++++++++++++++++++++--- 4 files changed, 69 insertions(+), 12 deletions(-) diff --git a/src/MiniDocs/Markdown.class.st b/src/MiniDocs/Markdown.class.st index 7145a0a..f9bea0c 100644 --- a/src/MiniDocs/Markdown.class.st +++ b/src/MiniDocs/Markdown.class.st @@ -84,12 +84,6 @@ Markdown >> contentsWithoutYAMLMetadata [ ^ newContents contents. ] -{ #category : #accessing } -Markdown >> defaultOptions [ - ^ { 'sourceCodeLink' -> true . - 'commentsProvider' -> 'Hypothesis' } asDictionary -] - { #category : #operation } Markdown >> deleteYAMLMetadata [ | newContents | @@ -134,6 +128,11 @@ Markdown >> exportAsFileOn: aFileReference [ stream nextPutAll: self contents withInternetLineEndings ]. ] +{ #category : #accessing } +Markdown >> exportAsHTML [ + ^ Pandoc markdownToHtml: self file +] + { #category : #operation } Markdown >> exportMetadataAsJson [ "TBD: Lua scripts should be checked and installed when missing. Maybe a shared location diff --git a/src/MiniDocs/Pandoc.class.st b/src/MiniDocs/Pandoc.class.st index 77b667a..f0d6bdd 100644 --- a/src/MiniDocs/Pandoc.class.st +++ b/src/MiniDocs/Pandoc.class.st @@ -122,12 +122,13 @@ Pandoc class >> markdownToHtml: inputFile [ Pandoc class >> markdownToHtmlOnUnix: inputFile [ | outputFile | - outputFile := FileLocator temp / (inputFile basenameWithoutExtension , '.html'). + + outputFile := inputFile parent / (inputFile basenameWithoutExtension , '.html'). outputFile ensureDelete. outputFile ensureCreateFile. OSSUnixSubprocess new command: 'pandoc'; - arguments: {'-f'. 'markdown+startnum+task_lists'. '-t'. 'html'. inputFile fullName. + arguments: {'-f'. 'markdown+startnum+task_lists'. '--standalone'. '-t'. 'html'. inputFile fullName. '--output'. outputFile fullName }; redirectStdout; redirectStderr; diff --git a/src/MiniDocs/PubPubContent.class.st b/src/MiniDocs/PubPubContent.class.st index d9a632f..2e66f56 100644 --- a/src/MiniDocs/PubPubContent.class.st +++ b/src/MiniDocs/PubPubContent.class.st @@ -5,7 +5,8 @@ Class { 'title', 'language', 'url', - 'thumbnail' + 'thumbnail', + 'work' ], #category : #'MiniDocs-Model' } @@ -66,6 +67,18 @@ PubPubContent >> language: aString [ language := aString ] +{ #category : #accessing } +PubPubContent >> next [ + ^ self nextInstance +] + +{ #category : #accessing } +PubPubContent >> previous [ + | index | + index := self work tableOfContents detectIndex: [:pubContent | pubContent = self ] ifNone: [ ^ nil ]. + ^ self work tableOfContents at: index - 1. +] + { #category : #accessing } PubPubContent >> printOn: aStream [ super printOn: aStream. @@ -112,3 +125,13 @@ PubPubContent >> url [ PubPubContent >> url: anObject [ url := anObject ] + +{ #category : #accessing } +PubPubContent >> work [ + ^ work +] + +{ #category : #accessing } +PubPubContent >> work: aPubPubWork [ + work := aPubPubWork +] diff --git a/src/MiniDocs/PubPubWork.class.st b/src/MiniDocs/PubPubWork.class.st index 7c0c70d..fcc95d6 100644 --- a/src/MiniDocs/PubPubWork.class.st +++ b/src/MiniDocs/PubPubWork.class.st @@ -45,6 +45,12 @@ PubPubWork >> currentLanguage: twoLettersInISO639_1 [ currentLanguage := twoLettersInISO639_1 ] +{ #category : #accessing } +PubPubWork >> defaultOptions [ + ^ { 'sourceCodeLink' -> true . + 'commentsProvider' -> 'Hypothesis' } asDictionary +] + { #category : #accessing } PubPubWork >> defaultTitle [ ^ self titles associations first value @@ -66,10 +72,29 @@ PubPubWork >> downloadContents [ ^ workingDirectory ] +{ #category : #accessing } +PubPubWork >> downloadContents2 [ + | workingDirectory | + workingDirectory := self folder / self currentLanguage / 'book'. + self tableOfContentsDictionary keysAndValuesDo: [ :name :chapterAddress | |currentFileName| + currentFileName := name, '--', chapterAddress, '.md'. + (workingDirectory / currentFileName) asFileReference ensureDelete. + (workingDirectory / 'markdown') asFileReference ensureDelete. + ZnClient new + get: self address, 'pub/', chapterAddress, '/download/markdown'; + downloadTo: workingDirectory . + workingDirectory / 'markdown' renameTo: currentFileName + ]. + ^ workingDirectory +] + { #category : #accessing } PubPubWork >> exportToHTML [ - ^ self markdownFiles - collect: [ :file | Markdown new fromFile: file ]. + self markdownFiles + do: [ :file | | doc | + doc := Markdown new fromFile: file. + doc exportAsHTML ]. + ^ self markdownFiles first parent ] { #category : #accessing } @@ -136,12 +161,21 @@ PubPubWork >> markdownFiles [ select: [ :file | file basename endsWith: '.md' ] ] +{ #category : #accessing } +PubPubWork >> populateContents [ + self tableOfContents isEmptyOrNil + ifTrue: [ self populateTableOfContents ]. + ^ self tableOfContents + +] + { #category : #accessing } PubPubWork >> populateTableOfContents [ | contentsCollection | contentsCollection := self extractRawTableOfContents collect: [:each | (PubPubContent fromXML: each) - language: self currentLanguage + language: self currentLanguage; + work: self ]. self addTableOfContents: contentsCollection asOrderedCollection ]