Improving table of contents management.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2024-03-19 07:27:38 -05:00
parent d876485db9
commit 1a380405a3
4 changed files with 69 additions and 12 deletions

View File

@ -84,12 +84,6 @@ Markdown >> contentsWithoutYAMLMetadata [
^ newContents contents. ^ newContents contents.
] ]
{ #category : #accessing }
Markdown >> defaultOptions [
^ { 'sourceCodeLink' -> true .
'commentsProvider' -> 'Hypothesis' } asDictionary
]
{ #category : #operation } { #category : #operation }
Markdown >> deleteYAMLMetadata [ Markdown >> deleteYAMLMetadata [
| newContents | | newContents |
@ -134,6 +128,11 @@ Markdown >> exportAsFileOn: aFileReference [
stream nextPutAll: self contents withInternetLineEndings ]. stream nextPutAll: self contents withInternetLineEndings ].
] ]
{ #category : #accessing }
Markdown >> exportAsHTML [
^ Pandoc markdownToHtml: self file
]
{ #category : #operation } { #category : #operation }
Markdown >> exportMetadataAsJson [ Markdown >> exportMetadataAsJson [
"TBD: Lua scripts should be checked and installed when missing. Maybe a shared location "TBD: Lua scripts should be checked and installed when missing. Maybe a shared location

View File

@ -122,12 +122,13 @@ Pandoc class >> markdownToHtml: inputFile [
Pandoc class >> markdownToHtmlOnUnix: inputFile [ Pandoc class >> markdownToHtmlOnUnix: inputFile [
| outputFile | | outputFile |
outputFile := FileLocator temp / (inputFile basenameWithoutExtension , '.html').
outputFile := inputFile parent / (inputFile basenameWithoutExtension , '.html').
outputFile ensureDelete. outputFile ensureDelete.
outputFile ensureCreateFile. outputFile ensureCreateFile.
OSSUnixSubprocess new OSSUnixSubprocess new
command: 'pandoc'; 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 }; '--output'. outputFile fullName };
redirectStdout; redirectStdout;
redirectStderr; redirectStderr;

View File

@ -5,7 +5,8 @@ Class {
'title', 'title',
'language', 'language',
'url', 'url',
'thumbnail' 'thumbnail',
'work'
], ],
#category : #'MiniDocs-Model' #category : #'MiniDocs-Model'
} }
@ -66,6 +67,18 @@ PubPubContent >> language: aString [
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 } { #category : #accessing }
PubPubContent >> printOn: aStream [ PubPubContent >> printOn: aStream [
super printOn: aStream. super printOn: aStream.
@ -112,3 +125,13 @@ PubPubContent >> url [
PubPubContent >> url: anObject [ PubPubContent >> url: anObject [
url := anObject url := anObject
] ]
{ #category : #accessing }
PubPubContent >> work [
^ work
]
{ #category : #accessing }
PubPubContent >> work: aPubPubWork [
work := aPubPubWork
]

View File

@ -45,6 +45,12 @@ PubPubWork >> currentLanguage: twoLettersInISO639_1 [
currentLanguage := twoLettersInISO639_1 currentLanguage := twoLettersInISO639_1
] ]
{ #category : #accessing }
PubPubWork >> defaultOptions [
^ { 'sourceCodeLink' -> true .
'commentsProvider' -> 'Hypothesis' } asDictionary
]
{ #category : #accessing } { #category : #accessing }
PubPubWork >> defaultTitle [ PubPubWork >> defaultTitle [
^ self titles associations first value ^ self titles associations first value
@ -66,10 +72,29 @@ PubPubWork >> downloadContents [
^ workingDirectory ^ 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 } { #category : #accessing }
PubPubWork >> exportToHTML [ PubPubWork >> exportToHTML [
^ self markdownFiles self markdownFiles
collect: [ :file | Markdown new fromFile: file ]. do: [ :file | | doc |
doc := Markdown new fromFile: file.
doc exportAsHTML ].
^ self markdownFiles first parent
] ]
{ #category : #accessing } { #category : #accessing }
@ -136,12 +161,21 @@ PubPubWork >> markdownFiles [
select: [ :file | file basename endsWith: '.md' ] select: [ :file | file basename endsWith: '.md' ]
] ]
{ #category : #accessing }
PubPubWork >> populateContents [
self tableOfContents isEmptyOrNil
ifTrue: [ self populateTableOfContents ].
^ self tableOfContents
]
{ #category : #accessing } { #category : #accessing }
PubPubWork >> populateTableOfContents [ PubPubWork >> populateTableOfContents [
| contentsCollection | | contentsCollection |
contentsCollection := self extractRawTableOfContents collect: [:each | contentsCollection := self extractRawTableOfContents collect: [:each |
(PubPubContent fromXML: each) (PubPubContent fromXML: each)
language: self currentLanguage language: self currentLanguage;
work: self
]. ].
self addTableOfContents: contentsCollection asOrderedCollection self addTableOfContents: contentsCollection asOrderedCollection
] ]