bernardodiasc / filestojson Goto Github PK
View Code? Open in Web Editor NEWGenerates JSON from static files [stable]
Home Page: https://bernardodiasc.github.io/filestojson/
License: MIT License
Generates JSON from static files [stable]
Home Page: https://bernardodiasc.github.io/filestojson/
License: MIT License
include
and exclude
arrays are only accepting a very specific format of data, this should be more flexible.
Resources:
include: ['.md', '.png'],
exclude: ['README.md'],
Example:
include: ['*.md', '*.png', '*.jpg', '*.gif', 'scriptsamples/**/*.js'],
exclude: ['README.md', 'foldername'],
Currently the script will generate a single JSON file.
The way the output files will be created need to be configurable. One simple use case is to have a single JSON for each content type, but this could be even more flexible.
Image files are stored together with content files, as they are content as well. The problem is that the content path is not public, therefore images aren't be accessible.
Images should be copied to a public place respecting original path structures from contents. This step need to be together with the data generation.
Looks like broken markdown can cause trouble with gh-pages and probably on data generation as well. Need to include a step somewhere somehow to avoid invalid stuff to be published.
Resources:
This one is already implemented here https://github.com/bernardodiasc/filestojson/tree/master/examples/plainjs
gallery
(required #9)Include unit tests for all functions.
For each Content Type there is a translation file that return the custom structured data based on an index of files of that kind.
content type from examples in this repo
// posts.js
function translation (content, contentType) {
let output = {}
const allFiles = content.filter(each => each.dir.includes(`/${contentType}`))
const index = allFiles.filter(each => each.base === 'index.md')[0]
index.attr.forEach(each => {
allFiles.forEach(file => {
if (file.name === each) {
output[each] = file
}
})
})
return output
}
export default translation
// gallery.js
function translation (content, contentType) {
let output = {}
const allFiles = content.filter(each => each.dir.includes(`/${contentType}`))
const index = allFiles.filter(each => each.base === 'index.md')[0]
index.attr.forEach(each => {
Object.keys(each).forEach(key => {
output[key] = Object.assign({ title: each[key] }, allFiles.filter(file => file.name === key)[0])
})
})
return output
}
export default translation
psedo-code bellow demonstrate what is the translation for each content type, the rest should be abstracted away to keep theses translations as simple as possible.
// posts.js
index.attr.forEach(each => {
allFiles.forEach(file => {
if (file.name === each) {
output[each] = file
}
})
})
// gallery.js
index.attr.forEach(each => {
Object.keys(each).forEach(key => {
output[key] = Object.assign({ title: each[key] }, allFiles.filter(file => file.name === key)[0])
})
})
When running filestojson ./tests/fixtures/config.js
, the config path is just a string and is also a relative path.
The config path argument need to return the actual config module.
As a developer, while editing existing or creating a new content type, I want to quickly preview that specific content type data structure on console in order to have simpler development experience.
./contents/posts
./contents/posts/index.md
and ./contents/posts/post-1.md
post-1
key/value in Posts Index:---
- post-1: Post 1
---
---
- title: Post 1
---
This is a sample post.
## Featuring Markdown
> actually Front-matter
- n
- i
- c
- e
filestojson --preview ./content/posts
(depends on #2) and get on console:# Posts content type
"posts": {
"post-1": {
"file": "/posts/post-1.md",
"dir": "/posts/post-1",
"name": "post-1",
"base": "post-1.md",
"ext": ".md",
"attr": {
"title":"Post 1",
},
"body": "This is a sample post.\n\n## Featuring Markdown\n\n> actually Front-matter\n\n- n\n- i\n- c\n- e\n"
}
}
Use Jest.
Currently only supporting .md
and .png
.
Support more textual types, more image types and maybe allow to include code types too (not to run the source code, but as a source of content, with proper treatment).
Currently the contentTypes
validation are limited to an array of object. It should define better the object shape.
contentTypes: Joi.array().min(1).items(Joi.object()).required(),
Example:
contentTypes: Joi.array().min(1).items(
Joi.object({
arg: Joi.string().required(),
value: Joi.func().required(),
})
).required(),
The problem with the snippet above is that is not valid for the need, using it just as pseudo-code.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.