diff --git a/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st b/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st index b4821433..dc144b82 100644 --- a/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st +++ b/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st @@ -74,14 +74,13 @@ MicBlogCreatorTest >> generateArchitecture [ ref2 writeStreamDo: [ :stream | stream nextPutAll: self fileContent2 ]. ref3 := fileSystem workingDirectory / 'source/anExample3.md'. - ref3 writeStreamDo: [ :stream | stream nextPutAll: self fileContent3 ]. - + ref3 writeStreamDo: [ :stream | stream nextPutAll: self fileContent3 ] ] { #category : 'as yet unclassified' } -MicBlogCreatorTest >> listOfFile [ +MicBlogCreatorTest >> listOfFile [ - ^ (fileSystem / 'source') allChildren select: [ :each | each isFile ] + ^ (fileSystem / 'source') allFiles ] { #category : 'running' } @@ -102,7 +101,7 @@ MicBlogCreatorTest >> testCollectAllMarkDownFile [ | fileList | - fileList := blog collectAllMarkDownFile. + fileList := blog collectAllMarkDownFile: blog sourceDirectory. self assert: fileList size equals: 3 ] @@ -119,26 +118,25 @@ MicBlogCreatorTest >> testCopySourceDirectoryInTarget [ MicBlogCreatorTest >> testCreateAllHtmlFile [ | allFile | - blog createAllHtmlFile. - allFile := (fileSystem / 'html') allChildren select: [ :each | - each isFile ]. + allFile := (fileSystem / 'html') allFiles. self assert: allFile size equals: 6 ] { #category : 'tests' } -MicBlogCreatorTest >> testCreateHtmlFile [ - - | root | - root := Microdown parse: - (fileSystem / 'source/anExample1.md') readStream. - blog - createHtmlFile: root. +MicBlogCreatorTest >> testCreateHtmlFileToReplace [ - self assert: - (fileSystem / 'html/2019/January/8/A Cool Story.html') exists + | root file | + + file := self listOfFile at: 1 . + + root := Microdown parse: file contents. + + MicBlogCreator new createHtmlFile: root toReplace: file. + + self assert: file basename equals: 'anExample1.html' ] { #category : 'tests' } @@ -159,7 +157,7 @@ MicBlogCreatorTest >> testCreateHtmlGroupFileAt [ blog createHtmlGroupFile: root at: (Month year: 2019 month: 'January'). - self assert: (fileSystem / 'html/2019/January/index.html') exists + self assert: (fileSystem / 'html/_monthBlog/January 2019.html') exists ] { #category : 'tests' } @@ -173,3 +171,41 @@ MicBlogCreatorTest >> testCreateHtmlSummarize [ self assert: (fileSystem / 'html/index.html') exists ] + +{ #category : 'tests' } +MicBlogCreatorTest >> testRenameMarkdownIntoHtmlFile [ + + | fileRef | + fileRef := MicBlogCreator new renameMarkdownIntoHtmlFile: + fileSystem / 'source/anExample1.md'. + + self assert: (fileSystem / 'source/anExample1.html') exists. + self assert: (fileSystem / 'source/anExample1.md') exists not +] + +{ #category : 'tests' } +MicBlogCreatorTest >> testRootAssembly [ + + | root file | + + file := self listOfFile at: 1. + root := Microdown parse: file contents. + + MicBlogCreator new rootAssembly: root. + + self assert: root children size equals: 5 +] + +{ #category : 'tests' } +MicBlogCreatorTest >> testWriteToNamed [ + + | root file html| + + file := self listOfFile at: 1. + root := Microdown parse: file contents. + html := (MicHTMLVisitor new visit: root) at: 1. + + MicBlogCreator new write: html to: fileSystem / 'html' named: 'test.html'. + + self assert: (fileSystem / 'html/test.html') exists +] diff --git a/src/Microdown-Blog/MicBlogCreator.class.st b/src/Microdown-Blog/MicBlogCreator.class.st index c72fbaaf..32710366 100644 --- a/src/Microdown-Blog/MicBlogCreator.class.st +++ b/src/Microdown-Blog/MicBlogCreator.class.st @@ -30,9 +30,9 @@ MicBlogCreator class >> createFrom: source to: target [ ] { #category : 'as yet unclassified' } -MicBlogCreator >> collectAllMarkDownFile [ +MicBlogCreator >> collectAllMarkDownFile: aFileReference [ - ^ sourceDirectory allFiles select: [ :each | + ^ aFileReference allFiles select: [ :each | each fullName endsWith: '.md' ] ] @@ -46,17 +46,26 @@ MicBlogCreator >> copySourceDirectoryInTarget [ MicBlogCreator >> createAllHtmlFile [ | allFile allFileParse sum summar | - allFile := self collectAllMarkDownFile. + self copySourceDirectoryInTarget. + allFile := self collectAllMarkDownFile: targetDirectory. allFileParse := allFile collect: [ :each | Microdown parse: each asFileReference contents ]. - allFileParse do: [ :each | self createHtmlFile: each ]. + 1 to: allFile size do: [ :index | + self + createHtmlFile: (allFileParse at: index) + toReplace: (allFile at: index) ]. + + sum := MicSummarizer new. sum targetDirectory: targetDirectory. self createHtmlSummarize: (sum summarizeFile: allFile). + "JUSQUE LA CA MARCHE" + targetDirectory fileSystem createDirectory: '/html/_monthBlog'. + MicMonthListCreator new generateDateListSince2014 do: [ :each | summar := sum group: allFileParse byDate: each. summar isNotEmpty ifTrue: [ @@ -65,44 +74,39 @@ MicBlogCreator >> createAllHtmlFile [ ] { #category : 'rendering' } -MicBlogCreator >> createHtmlFile: aMicRoot [ +MicBlogCreator >> createHtmlFile: aMicRoot toReplace: aFileReference [ - | a q date header fileRef | + | html | self rootAssembly: aMicRoot. + html := (MicHTMLVisitor new visit: aMicRoot) at: 1. + + self renameMarkdownIntoHtmlFile: aFileReference. - a := (MicHTMLVisitor new visit: aMicRoot) at: 1. - - date := (aMicRoot children at: 1) body at: #date. - date := date asDate. - header := MicSingleSummarizer new firstHeaderBlockOf: aMicRoot. - - fileRef := targetDirectory copyWithPath: - targetDirectory fullPath asUrl path , '/' - , date year asString , '/' , date monthName , '/' - , date day asString , '/'. + aFileReference delete. - self write: a to: fileRef named: header text . + self + write: html + to: aFileReference parent + named: (aFileReference fullName substrings: '/') last ] { #category : 'rendering' } MicBlogCreator >> createHtmlGroupFile: aMicRoot at: aDate [ - | a q fileRef | + | a fileRef | self rootAssembly: aMicRoot. a := (MicHTMLVisitor new visit: aMicRoot) at: 1. - fileRef := targetDirectory copyWithPath: - targetDirectory fullPath asUrl path , '/' - , aDate year asString , '/' , aDate monthName , '/'. + fileRef := targetDirectory / '_monthBlog'. - self write: a to: fileRef named: 'index' . + self write: a to: fileRef named: aDate asString,'.html' ] { #category : 'rendering' } MicBlogCreator >> createHtmlSummarize: aMicRoot [ - | a q fileRef | + | a fileRef | self rootAssembly: aMicRoot. a := (MicHTMLVisitor new visit: aMicRoot) at: 1. @@ -110,7 +114,17 @@ MicBlogCreator >> createHtmlSummarize: aMicRoot [ fileRef := targetDirectory copyWithPath: targetDirectory fullPath asUrl path. - self write: a to: fileRef named: 'index' . + self write: a to: fileRef named: 'index.html' +] + +{ #category : 'rendering' } +MicBlogCreator >> renameMarkdownIntoHtmlFile: aFileReference [ + + | newPath | + + newPath := aFileReference fullName copyReplaceAll: '.md' with: '.html'. + + aFileReference renameTo: newPath ] { #category : 'as yet unclassified' } @@ -158,7 +172,7 @@ MicBlogCreator >> write: aMicHTMLVisitor to: aPath named: aName [ setCharSetUTF8; destinationPath: aPath. ^ htmlDocument - fileName: aName , '.html'; + fileName: aName; writeDocument: aMicHTMLVisitor contents; contents ]