From 8b706ceefba6fbfe82cad786d8062e4dcba3edc6 Mon Sep 17 00:00:00 2001 From: "quentin.moutte.etu" Date: Tue, 11 Jun 2024 17:02:31 +0200 Subject: [PATCH 1/2] Delete all month file and link with no one file --- .../MicMonthListCreatorTest.class.st | 21 +++++++++ src/Microdown-Blog/MicBlogCreator.class.st | 47 ++++++++++++------- .../MicMonthListCreator.class.st | 10 +++- 3 files changed, 59 insertions(+), 19 deletions(-) diff --git a/src/Microdown-Blog-Tests/MicMonthListCreatorTest.class.st b/src/Microdown-Blog-Tests/MicMonthListCreatorTest.class.st index 995bff7b..111962df 100644 --- a/src/Microdown-Blog-Tests/MicMonthListCreatorTest.class.st +++ b/src/Microdown-Blog-Tests/MicMonthListCreatorTest.class.st @@ -43,3 +43,24 @@ MicMonthListCreatorTest >> testGenerateMicListBlockOfLinkDateTo [ equals: '[' , Date today month asString , '](/html/_monthBlog/' , Date today month name , '_' , Date today year asString, '.html)' ] + +{ #category : 'tests' } +MicMonthListCreatorTest >> testGenerateMicListBlockOfLinkDateWithTo [ + + | dateList fileSystem | + fileSystem := FileSystem memory. + fileSystem createDirectory: '/html'. + + dateList := MicMonthListCreator new + generateMicListBlockOfLinkDateTo: + fileSystem workingDirectory / '/html'. + + self assert: (dateList isKindOf: MicUnorderedListBlock). + self + assert: dateList children size equals: self numberOfMonthSince2014; + assert: dateList children first children first plainText + equals: '[January 2014](/html/_monthBlog/January_2014.html)'; + assert: dateList children last children first plainText + equals: '[' , Date today month asString , '](/html/_monthBlog/' + , Date today month name , '_' , Date today year asString , '.html)' +] diff --git a/src/Microdown-Blog/MicBlogCreator.class.st b/src/Microdown-Blog/MicBlogCreator.class.st index 977851b3..79a67b9e 100644 --- a/src/Microdown-Blog/MicBlogCreator.class.st +++ b/src/Microdown-Blog/MicBlogCreator.class.st @@ -52,9 +52,7 @@ MicBlogCreator >> copySourceDirectoryInTarget [ { #category : 'rendering' } MicBlogCreator >> createAllHtmlFile [ - | allFile allFileParse sum summar listOfSingleSummarize | - dateList := MicMonthListCreator new - generateMicListBlockOfLinkDateTo: targetDirectory. + | allFile allFileParse sum listOfSingleSummarize | "Copy the source directory in the target directory" self copySourceDirectoryInTarget. @@ -64,6 +62,9 @@ MicBlogCreator >> createAllHtmlFile [ (Microdown parse: each asFileReference contents) fromFile: each ]. + "Create _monthListBlog" + self initializeMonthList: allFileParse. + "transform all markdown file into html file" allFileParse do: [ :each | self createHtmlFile: each toReplace: each fromFile ]. @@ -75,20 +76,7 @@ MicBlogCreator >> createAllHtmlFile [ listOfSingleSummarize := allFileParse collect: [ :each | MicSingleSummarizer new summarize: each ]. - self createHtmlSummarize: (sum summarize: listOfSingleSummarize). - - "Create the directory with all month summarizer in html" - - targetDirectory fileSystem createDirectory: - targetDirectory fullName , '/_monthBlog'. - - MicMonthListCreator new generateDateListSince2014 do: [ :each | - summar := sum group: listOfSingleSummarize byDate: each. - summar isNotEmpty - ifTrue: [ - summar := sum summarize: summar. - self createHtmlGroupFile: summar at: each ] - ifFalse: [ self createHtmlEmptyGroupFileAt: each ] ] + self createHtmlSummarize: (sum summarize: listOfSingleSummarize) ] { #category : 'rendering' } @@ -155,6 +143,31 @@ MicBlogCreator >> dateList: aDateList [ dateList := aDateList. ] +{ #category : 'rendering' } +MicBlogCreator >> initializeMonthList: listOfSingleSummarize [ + + | summar sum date | + sum := MicSummarizer new. + sum targetDirectory: targetDirectory. + + dateList := MicMonthListCreator new generateDateListSince2014. + + dateList do: [ :each | + summar := sum group: listOfSingleSummarize byDate: each. + summar isEmpty ifTrue: [ dateList := dateList copyWithout: each ] ]. + + date := dateList copy. + + dateList := MicMonthListCreator new + generateMicListBlockOfLinkDateWith: dateList + To: targetDirectory. + + date do: [ :each | + summar := sum group: listOfSingleSummarize byDate: each. + summar := sum summarize: summar. + self createHtmlGroupFile: summar at: each ] +] + { #category : 'rendering' } MicBlogCreator >> renameMarkdownIntoHtmlFile: aFileReference [ diff --git a/src/Microdown-Blog/MicMonthListCreator.class.st b/src/Microdown-Blog/MicMonthListCreator.class.st index 385fdde9..e31d4448 100644 --- a/src/Microdown-Blog/MicMonthListCreator.class.st +++ b/src/Microdown-Blog/MicMonthListCreator.class.st @@ -22,14 +22,20 @@ MicMonthListCreator >> generateDateListSince2014 [ { #category : 'generate' } MicMonthListCreator >> generateMicListBlockOfLinkDateTo: aFileReference [ + ^ self generateMicListBlockOfLinkDateWith: self generateDateListSince2014 To: aFileReference +] + +{ #category : 'generate' } +MicMonthListCreator >> generateMicListBlockOfLinkDateWith: aDateList To: aFileReference [ + | root link listElement disk | root := MicUnorderedListBlock new. (aFileReference fileSystem store isKindOf: WindowsStore) ifTrue: [ - disk := 'File:///', aFileReference fileSystem store currentDisk ]. + disk := 'File:///' , aFileReference fileSystem store currentDisk ]. disk ifNil: [ disk := '' ]. - self generateDateListSince2014 do: [ :each | + aDateList do: [ :each | listElement := MicListItemBlock new. link := self makeALink: each asString From 9ae0eac0ea7d41a8b044116d00425656d2325743 Mon Sep 17 00:00:00 2001 From: "quentin.moutte.etu" Date: Thu, 13 Jun 2024 15:19:00 +0200 Subject: [PATCH 2/2] add test for initializeMonthList --- .../MicBlogCreatorTest.class.st | 22 +++++++++++++++---- src/Microdown-Blog/MicBlogCreator.class.st | 3 ++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st b/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st index e8d90817..f3d3d925 100644 --- a/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st +++ b/src/Microdown-Blog-Tests/MicBlogCreatorTest.class.st @@ -144,16 +144,14 @@ MicBlogCreatorTest >> testCreateAllHtmlFile [ { #category : 'tests' } MicBlogCreatorTest >> testCreateFromTo [ - | allFile nbMonthFile | + | allFile | MicBlogCreator createFrom: fileSystem / 'source' to: fileSystem / 'html'. allFile := (fileSystem / 'html') allFiles. - - nbMonthFile := (Date today year - 2014) * 12 + Date today month index. - self assert: allFile size equals: 5 + nbMonthFile + self assert: allFile size equals: 7 ] { #category : 'tests' } @@ -220,6 +218,22 @@ MicBlogCreatorTest >> testCreateHtmlSummarize [ self assert: (fileSystem / 'html/index.html') exists ] +{ #category : 'tests' } +MicBlogCreatorTest >> testInitializeMonthList [ + + | listSingleSummarizer | + + listSingleSummarizer := Array new: 3. + +listSingleSummarizer at:1 put: (MicSingleSummarizer new summarizeFile: fileSystem / 'source/anExample1.md'). +listSingleSummarizer at:2 put: (MicSingleSummarizer new summarizeFile: fileSystem / 'source/anExample2.md'). +listSingleSummarizer at:3 put: (MicSingleSummarizer new summarizeFile: fileSystem / 'source/test/anExample3.md'). + + blog initializeMonthList: listSingleSummarizer. + +self assert: (fileSystem / 'html/_monthBlog') allFiles size equals: 2. +] + { #category : 'tests' } MicBlogCreatorTest >> testRenameMarkdownIntoHtmlFile [ diff --git a/src/Microdown-Blog/MicBlogCreator.class.st b/src/Microdown-Blog/MicBlogCreator.class.st index 79a67b9e..370d0c06 100644 --- a/src/Microdown-Blog/MicBlogCreator.class.st +++ b/src/Microdown-Blog/MicBlogCreator.class.st @@ -151,8 +151,9 @@ MicBlogCreator >> initializeMonthList: listOfSingleSummarize [ sum targetDirectory: targetDirectory. dateList := MicMonthListCreator new generateDateListSince2014. + date := dateList copy. - dateList do: [ :each | + date do: [ :each | summar := sum group: listOfSingleSummarize byDate: each. summar isEmpty ifTrue: [ dateList := dateList copyWithout: each ] ].