Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve content type translation functions #6

Open
bernardodiasc opened this issue Aug 20, 2017 · 0 comments
Open

Improve content type translation functions #6

bernardodiasc opened this issue Aug 20, 2017 · 0 comments

Comments

@bernardodiasc
Copy link
Owner

bernardodiasc commented Aug 20, 2017

For each Content Type there is a translation file that return the custom structured data based on an index of files of that kind.

Actual

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

Expected

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])
    })
  })
@bernardodiasc bernardodiasc added this to To Do in Library package Aug 20, 2017
@bernardodiasc bernardodiasc modified the milestone: Enhancements Aug 20, 2017
@bernardodiasc bernardodiasc changed the title Improve content type translations Improve content type translation functions Aug 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

1 participant