Git Product home page Git Product logo

json-yaml-front-matter's Introduction

Hi there ๐Ÿ‘‹ I am Sachin Sancheti

  • ๐Ÿ“ซ How to reach me: Email Me!! LinkedIn
  • ๐Ÿ“ซ How to physically reach me: I live in Coonoor, The Nilgiris, Tamil Nadu, India
  • ๐Ÿ”ญ I Studied at: Coonoorian, studied at HIHS, SJC in Coonoor, CIRS in Coimbatore, NUS in Singapore (BBA with Statistics)
  • โšก Fun fact: Vegetarian, know a good number of people around here
  • ๐Ÿ’ฌ Ask me about: anything...
  • ๐Ÿ”ญ Iโ€™m currently working as a Conceptualization, Salesman, Worksman at Vitrag Group
  • ๐Ÿ˜„ Pronouns: prudent, keen learner, emperical, shape dreamer
  • ๐Ÿ‘ฏ Iโ€™m not looking to collaborate with anyone, though you may feel free to view and use my code for good things

Recently learnt

  • basic html, css, js
  • React
  • Sveltekit
  • Familiarizing myself with CMS like Sanity and Hygraph
  • 11ty static site generator
  • R
  • some linux commands for productivity

My GitHub Stats

kritikapattalam

Top Languages

Top Langs

What Netlify has to say

Netlify usage stats in 2021

json-yaml-front-matter's People

Contributors

imgbotapp avatar sachinsancheti1 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

json-yaml-front-matter's Issues

Using const instead of var

Hi @sachinsancheti1!
Over in the eleventy repo you mentioned, that you'd accept feedback on this repo (even if your CONTRIBUTING.md tells otherwise).

Here comes mine :-)

From what I can tell, those variables aren't reassigned, so you could use const instead of var:

var jsonData = fs.readFileSync('_site/_data/properties.json');
var jsonObj = JSON.parse(jsonData)[0]; // capturing only the first element. I am sure there is a way to do this using a foreach loop.

var slug = jsonObj.websiteLink;
var filename = slug+".md";

Prefer async over sync code execution

I know, it is meant as script, but in

var jsonData = fs.readFileSync('_site/_data/properties.json');

you're calling code synchronously. A better way would be to put the logic inside a function and call it afterwards.

By using es6-promisify you could turn fs.readFile into a Promise-based API. By using an async function you could then use await to read the file.

The code could look akin to this:

const defaultFilePath = '_site/_data/properties.json';
let outputFileName = 'rename-me';

async function makeTemplate () {
  const properties = await readAsJson(defaultFilePath);

  if (!properties.message) {
    return writeFile(properties);
  } else {
    console.log(properties.message);
  }
}

async function readAsJson (filePath) {
  const jsonData = await fs.readFile(filePath, 'utf8');
  return = JSON.parse(jsonData)[0];  // This could potentially fail!
}

function writeFile (properties) {
  const output = computeOutput(properties);
  outputFileName = getOutputFileName(properties);

  try {
    return fs.writeFile(outputFileName, output, 'utf8');
  } catch (reason) {
    console.error('An error occured while writing JSON Object to file.');
    return console.error(reason);
  }
}

function computeOutput (properties) {
  const frontmatter = yaml.safeDump(properties);
  return `---\n${yamlStr}\n---`;
}

function getOutputFileName (properties) {
  return `_site/houses-for-sale/${properties.websiteLink}.md`
}

makeTemplate();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.