Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Javarome committed Sep 16, 2024
1 parent b9e3a5f commit ab53280
Show file tree
Hide file tree
Showing 377 changed files with 3,885 additions and 2,982 deletions.
71 changes: 67 additions & 4 deletions .idea/csv-editor.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added BB_Unknowns.pdf
Binary file not shown.
3 changes: 2 additions & 1 deletion DefaultContentVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export class DefaultContentVisitor implements ContentVisitor {
async visit(context: HtmlRR0SsgContext) {
const dirName = path.dirname(context.file.name)
const dataList = await this.service.getFromDir(dirName,
["people", "case", "sighting", "api", "product", "org"], ["index.json", "case.json", "people.json"])
["people", "case", "sighting", "api", "product", "org"],
["index.json", "case.json", "people.json", "api.json", "org.json"])
if (dataList.length > 0) {
for (const data of dataList) {
switch (data.type) {
Expand Down
2 changes: 1 addition & 1 deletion RR0ContentStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class RR0ContentStep extends ContentStep<HtmlRR0SsgContext> {
context.time.setYear(newTimeContext.getYear())
context.time.setMonth(newTimeContext.getMonth())
context.time.setDayOfMonth(newTimeContext.getDayOfMonth())
context.time.from = context.time
// context.time.from = context.time
}
return newTimeContext
}
Expand Down
2 changes: 2 additions & 0 deletions book/BookBuddy.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Title,Original Title,Subtitle,Series,Volume,Author,"Author (Last, First)",Illustrator,Narrator,Translator,Photographer,Editor,Publisher,Place of Publication,Date Published,Year Published,Original Date Published,Original Year Published,Edition,Genre,Summary,Guided Reading Level,Lexile Measure,Lexile Code,Grade Level Equivalent,Developmental Reading Assessment,Interest Level,AR Level,AR Points,AR Quiz Number,Word Count,Number of Pages,Format,Audio Runtime,Dimensions,Weight,List Price,Language,Original Language,DDC,LCC,LCCN,OCLC,ISBN,ISSN,Favorites,Rating,Physical Location,Status,Status Incompleted Reason,Status Hidden,Date Started,Date Finished,Current Page,Loaned To,Date Loaned,Borrowed From,Date Borrowed,Returned from Borrow,Not Owned Reason,Quantity,Condition,Recommended By,Date Added,User Supplied ID,User Supplied Descriptor,Tags,Purchase Date,Purchase Place,Purchase Price,Notes,Google VolumeID,Category,Wish List,Previously Owned,Up Next,Position,Uploaded Image URL,Activities
Chroniques des apparitions extra-terrestres,,du folklore aux soucoupes volantes,,,Jacques Vallée,"Vallée, Jacques",,,,,,J'ai lu,,,1974,,,,,,,,,,,,,,,,307,,,,,,français,,,,,,,,0,0.000000,,Unread,,0,,,,,,,,0,,,,,2023/04/27 00:32:12.327097892,,,,,,,,SwmxNAAACAAJ,Personnel,0,0,0,,https://m.media-amazon.com/images/I/81oKXbcGMfL.jpg,
29 changes: 13 additions & 16 deletions book/BookImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { PeopleFactory } from "../people/PeopleFactory"
import { RR0EventFactory } from "../event/RR0EventFactory"
import { TypedDataFactory } from "../data/TypedDataFactory"
import path from "path"
import { glob } from "glob"

interface BookImportArgs {
import: string
Expand All @@ -19,21 +18,19 @@ const logger = new ConsoleLogger("rr0-books")
const args = new CLI().getArgs<BookImportArgs>()
const fileName = args.import
const dry = args.dry === "true"
const peopleFactory = new PeopleFactory(new RR0EventFactory())
const eventFactory = new RR0EventFactory()
const bookFactory = new TypedDataFactory(eventFactory, "book")
const dataService = new AllDataService([bookFactory])
const bookFactory = new TypedDataFactory<Book>(eventFactory, "book")
const dataService = new AllDataService([bookFactory, peopleFactory])

glob("people/*/*").then(peopleFiles => {
const peopleFactory = new PeopleFactory(new RR0EventFactory())
const outDir = "out"
const config: SsgConfig = {
getOutputPath(context: SsgContext): string {
return path.join(outDir, context.file.name)
}
const outDir = "out"
const config: SsgConfig = {
getOutputPath(context: SsgContext): string {
return path.join(outDir, context.file.name)
}
const books = new BookService(logger, dry, new PeopleService(dataService, peopleFactory), config)
books.import(fileName).then((result: Book[]) => {
logger.log("Wrote", result.length, "books")
}
)
})
}
const books = new BookService(logger, dry, new PeopleService(dataService, peopleFactory), config)
books.import(fileName).then((result: Book[]) => {
logger.log("Wrote", result.length, "books")
}
)
41 changes: 22 additions & 19 deletions book/BookService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as fs from "fs"
import { CSVFileReader } from "../../../@javarome/ssg-api/src/file/CSVFileReader"
import { FileUtil, Logger, SsgConfig } from "ssg-api"
import { TimeContext } from "../time/TimeContext"
import { TimeUrlBuilder } from "../time/TimeUrlBuilder"
Expand All @@ -9,6 +8,7 @@ import { Book } from "./Book"
import { People } from "../people/People"
import { RR0FileUtil } from "../util/file/RR0FileUtil"
import { PeopleService } from "../people/PeopleService"
import { CSVFileReader } from "../CSVFileReader"

export class BookService {

Expand Down Expand Up @@ -40,12 +40,7 @@ export class BookService {
const columns = [COLUMN_TITLE, "Original Title", COLUMN_SUBTITLE, COLUMN_SERIES, "Volume", COLUMN_AUTHOR, COLUMN_AUTHOR_LAST_FIRST, COLUMN_PUBLISHER, COLUMN_YEAR_PUBLISHED, "Original Year Published", "Genre", COLUMN_SUMMARY, "Number of Pages", "Language", COLUMN_ISBN, "Rating", "Notes", "Google VolumeID", "Uploaded Image URL"]
const readStream = fs.createReadStream(fileName)
const csvSeparator = ","
const reader = new CSVFileReader<Record<string, string>>(
readStream,
this.logger,
columns,
csvSeparator
)
const reader = new CSVFileReader<Record<string, string>>(readStream, this.logger, columns, csvSeparator)
const results = await reader.read()
const books: Book[] = []
for (const result of results) {
Expand All @@ -60,16 +55,25 @@ export class BookService {
const authorsNames = author ? author.split(",") : [authorLastFirst]
const authors: People[] = []
for (const authorName of authorsNames) {
const authorFound = await this.findPeople(authorName)
if (authorFound) {
authors.push(authorFound)
const author = await this.findPeople(authorName)
if (author) {
authors.push(author)
}
}
const publisher = result[COLUMN_PUBLISHER]
const authorsLastNames = authors.map(author => author.lastName).join("-")
const dirName = (authorsLastNames.length > 0 ? authorsLastNames : authorsNames.map(StringUtil.textToCamel))
+ "_" + StringUtil.capitalizeFirstLetter(StringUtil.textToCamel(title.toLowerCase()))
+ "_" + StringUtil.capitalizeFirstLetter(StringUtil.textToCamel(publisher))
const authorsLastNames = authors.map(author => author.lastName)
const titleStr = StringUtil.capitalizeFirstLetter(StringUtil.textToCamel(title.toLowerCase()))
const publisherStr = StringUtil.capitalizeFirstLetter(StringUtil.textToCamel(publisher))
let authorsStr = (authorsLastNames.length > 0 ? authorsLastNames : authorsNames.map(
StringUtil.textToCamel)).join("-")
let dirName: string
const andAl = "-and-al"
do {
dirName = StringUtil.removeAccents(`${authorsStr}_${titleStr}_${publisherStr}`)
if (dirName.length >= 255) {
authorsStr = authorsStr.substring(0, authorsStr.length - andAl.length - 1) + andAl
}
} while (dirName.length >= 255)
const parentDir = TimeUrlBuilder.fromContext(time)
const bookDir = path.join(parentDir, dirName)
const id = result[COLUMN_ISBN]
Expand All @@ -87,11 +91,11 @@ export class BookService {
summary,
variants: []
}
const authorStr = authors?.map(author => author.dirName)
const authorDir = authors?.map(author => author.dirName)
if (fs.existsSync(bookDir)) {
this.logger.log("Book directory", bookDir, "already exists, with authors", authorStr)
this.logger.log("Book directory", bookDir, "already exists, with authors", authorDir)
} else {
this.logger.log("Creating book directory", bookDir, "with authors", authorStr)
this.logger.log("Creating book directory", bookDir, "with authors", authorDir)
if (!this.dry) {
fs.mkdirSync(bookDir)
}
Expand All @@ -111,8 +115,7 @@ export class BookService {

protected async findPeople(fullName: string): Promise<People | undefined> {
if (this.peopleList.length <= 0) {
const peopleDirectories = RR0FileUtil.findDirectoriesContaining("people*.json")
this.peopleList = await this.peopleService.getFromDirs(peopleDirectories)
this.peopleList = await this.peopleService.getAll()
}
return this.peopleList.find(people => people.firstAndLastName === fullName)
}
Expand Down
10 changes: 10 additions & 0 deletions book/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Books

## Importation

Books datababase can be imported:

1. Export the BookBuddy database as a CSV file
2. Execute `npm run books` or run `BookImport --import BookBuddy.csv`

(Note: if you want to test the result of an import without actually importing, add the `--dry true` parameter)
Loading

0 comments on commit ab53280

Please sign in to comment.