Associating PubPubContents to their respective files.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2024-03-20 11:03:46 -05:00
parent 6c4fc47900
commit f2b41dd546
2 changed files with 49 additions and 13 deletions

View File

@ -6,7 +6,8 @@ Class {
'language', 'language',
'url', 'url',
'thumbnail', 'thumbnail',
'work' 'work',
'contents'
], ],
#category : #'MiniDocs-Model' #category : #'MiniDocs-Model'
} }
@ -40,6 +41,16 @@ PubPubContent >> asMarkdeepFrontPageElement [
^ response contents ^ response contents
] ]
{ #category : #accessing }
PubPubContent >> contents: anObject [
contents := anObject
]
{ #category : #accessing }
PubPubContent >> fileName [
^ self shortName,'--', self id, '.md'
]
{ #category : #accessing } { #category : #accessing }
PubPubContent >> fromXML: aXMLElement [ PubPubContent >> fromXML: aXMLElement [
| image anchor| | image anchor|

View File

@ -35,6 +35,12 @@ PubPubWork >> address: anUrl [
address := anUrl address := anUrl
] ]
{ #category : #accessing }
PubPubWork >> bookishFolder [
^ { 'en' -> 'book'.
'es' -> 'libro'} asDictionary
]
{ #category : #accessing } { #category : #accessing }
PubPubWork >> currentLanguage [ PubPubWork >> currentLanguage [
^ currentLanguage ^ currentLanguage
@ -59,16 +65,17 @@ PubPubWork >> defaultTitle [
{ #category : #accessing } { #category : #accessing }
PubPubWork >> downloadContents [ PubPubWork >> downloadContents [
| workingDirectory | | workingDirectory |
workingDirectory := self folder / self currentLanguage / 'book'. workingDirectory := self workingDirectory.
self tableOfContentsDictionary keysAndValuesDo: [ :name :chapterAddress | |currentFileName| self tableOfContentsDictionary
currentFileName := name, '--', chapterAddress, '.md'. keysAndValuesDo: [ :name :chapterAddress |
| currentFileName |
currentFileName := name , '--' , chapterAddress , '.md'.
(workingDirectory / currentFileName) asFileReference ensureDelete. (workingDirectory / currentFileName) asFileReference ensureDelete.
(workingDirectory / 'markdown') asFileReference ensureDelete. (workingDirectory / 'markdown') asFileReference ensureDelete.
ZnClient new ZnClient new
get: self address, 'pub/', chapterAddress, '/download/markdown'; get: self address , 'pub/' , chapterAddress , '/download/markdown';
downloadTo: workingDirectory . downloadTo: workingDirectory.
workingDirectory / 'markdown' renameTo: currentFileName workingDirectory / 'markdown' renameTo: currentFileName ].
].
^ workingDirectory ^ workingDirectory
] ]
@ -165,8 +172,12 @@ PubPubWork >> markdownFiles [
PubPubWork >> populateContents [ PubPubWork >> populateContents [
self tableOfContents isEmptyOrNil self tableOfContents isEmptyOrNil
ifTrue: [ self populateTableOfContents ]. ifTrue: [ self populateTableOfContents ].
^ self tableOfContents self workingDirectory children ifEmpty: [self downloadContents].
self tableOfContents do: [:pubPubContent | | contentFile|
contentFile := self workingDirectory / pubPubContent fileName.
contentFile exists
ifTrue: [ pubPubContent contents: (Markdown new fromFile: contentFile) ]
]
] ]
{ #category : #accessing } { #category : #accessing }
@ -213,3 +224,17 @@ PubPubWork >> tableOfContentsDictionary [
PubPubWork >> titles [ PubPubWork >> titles [
^ titles ifNil: [titles := OrderedDictionary new] ^ titles ifNil: [titles := OrderedDictionary new]
] ]
{ #category : #accessing }
PubPubWork >> viewContentsFor: aView [
<gtView>
^ aView list
title: 'Contents';
priority: 10;
items: [ self tableOfContents ]
]
{ #category : #accessing }
PubPubWork >> workingDirectory [
^ self folder / self currentLanguage / (self bookishFolder at: self currentLanguage)
]