Closed olayway closed 1 year ago
Latest commit: e4fefdcc280ab90d1534f5931d918dc6df9999d9
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
My only concern is that we would need some sort of query by folder functionality to replace our current implementation of markdowndb on datahub-next, because otherwise we would have to modify all the files so that those would have the correct filetype (if I understood it right).
Got it. I'll bring this functionality back!
Name | Link |
---|---|
Latest commit | e4fefdcc280ab90d1534f5931d918dc6df9999d9 |
Latest deploy log | https://app.netlify.com/sites/spectacular-dragon-c1015c/deploys/642c28e0d68c1d0008636d75 |
Deploy Preview | https://deploy-preview-472--spectacular-dragon-c1015c.netlify.app |
Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site settings.
Closes datopian/markdowndb#12
Motivation
As we plan to replace Contentlayer with our MarkdownDB package, we need a solid base upon which we can build a full-fledged "content-layer" solution. As the code in its current state is pretty hard to reason about and manipulate and is rather weakly typed, the development of any new functionality on top of it would only make it harder and harder to engineer, adjust and test. This PR aims to make the development of new features easier and (because of stronger typing) less error-prone.
Note, there is still quite a lot of room for improvement - TODOs comments were left in the code but will probably be resolved after further discussions on implementation design.
Changes
markdowndb.ts
cleaned up and refactored. Most notably:schema.ts
and bound with relevant classes corresponding to tables (see below)indexFolder
bound with MarkdownDB class as a methodinit
method onMarkdownDB
nowquery
method withgetFiles
getFileByUrl
andgetFileById
method to retrieve single file file from the db (e.g. for finding its backlinks)getLinks
method which supports querying back- or forward linkstypes.ts
classes inschema.ts
can also by used as types. Other types like e.g.DatabaseQuery
moved directly to method signature, as they are striclty bound with it and it's not needed to have it in a separate file (there is no other use case for it)markdowndb
lib and split into smaller unit tests grouped by tested functionalitiesschema.ts
created with four classes:File
,Link
,Tag
andFileTag
files
,links
,tags
,file_tags
and so it describes the fields (columns) existent on each table and has methods for creating a table, deleting it and batch-inserting data to itutils
folder created withrecursiveWalkDir.ts
,parseFile.ts
andextractWikiLinks.ts
each with its own, separate test suite