this repo has no description www.baileykane.co/
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

lib/bskyApi.js

BK610 02fd70a4 b5e66d73

+22 -36
+11
lib/sheetsConnector.js
··· 16 16 export function parseCSV(csvData) { 17 17 return Papa.parse(csvData, { header: true }); 18 18 } 19 + 20 + /**Convenience function to fetch CSV data from the provided Google Sheets URL 21 + * and parse it into an array of JSON objects, all in one. 22 + * 23 + * Combines getSheetsCSV and parseCSV. 24 + */ 25 + export async function importCSVDataAsJson(url) { 26 + const csv = await getSheetsCSV(url); 27 + const json = parseCSV(csv); 28 + return json; 29 + }
+4 -22
pages/music.js
··· 3 3 import Head from "next/head"; 4 4 import MusicItem from "../components/MusicItem"; 5 5 import PageHeading from "../components/PageHeading"; 6 - import { getSheetsCSV, parseCSV } from "../lib/sheetsConnector"; 6 + import { importCSVDataAsJson } from "../lib/sheetsConnector"; 7 7 8 8 export default class Music extends Component { 9 9 static async getInitialProps() { 10 - const musicList = await importMusic(); 10 + const musicList = await importCSVDataAsJson( 11 + process.env.NEXT_PUBLIC_MUSIC_DATA_URL 12 + ); 11 13 return { musicList }; 12 14 } 13 15 ··· 35 37 ); 36 38 } 37 39 } 38 - 39 - const importMusic = async () => { 40 - const musicCsv = await getSheetsCSV(process.env.NEXT_PUBLIC_MUSIC_DATA_URL); 41 - const musicJson = parseCSV(musicCsv); 42 - return musicJson; 43 - }; 44 - 45 - // const importMusic = async () => { 46 - // // From https://github.com/masives/netlifycms-nextjs/blob/master/pages/blog/index.js 47 - // const markdownFiles = require 48 - // .context("../content/music", false, /\.md$/) 49 - // .keys() 50 - // .map((relativePath) => relativePath.substring(2)); 51 - // return Promise.all( 52 - // markdownFiles.map(async (path) => { 53 - // const markdown = await import(`../content/music/${path}`); 54 - // return { ...markdown, slug: path.substring(0, path.length - 3) }; 55 - // }) 56 - // ); 57 - // };
+3 -4
pages/recipes/[slug].js
··· 2 2 import MissingContent from "../../components/MissingContent"; 3 3 import { micromark } from "micromark"; 4 4 import BaseLayout from "../../components/BaseLayout"; 5 - import { getSheetsCSV, parseCSV } from "../../lib/sheetsConnector"; 5 + import { importCSVDataAsJson } from "../../lib/sheetsConnector"; 6 6 7 7 export default class Recipe extends Component { 8 8 static async getInitialProps({ query }) { 9 9 const { slug } = query; 10 10 11 - const recipesCsv = await getSheetsCSV( 11 + const recipesList = await importCSVDataAsJson( 12 12 process.env.NEXT_PUBLIC_RECIPES_DATA_URL 13 13 ); 14 - const recipesJson = parseCSV(recipesCsv); 15 14 16 15 // TODO: Pulling all recipe data just to search for the one that matches the slug is inefficient. 17 16 // Consider pulling these once, elsewhere, and passing the correct recipe to this component. 18 - const recipe = recipesJson.data.find((recipe) => recipe.slug === slug); 17 + const recipe = recipesList.data.find((recipe) => recipe.slug === slug); 19 18 20 19 return { recipe }; 21 20 }
+4 -10
pages/recipes/index.js
··· 3 3 import BaseLayout from "../../components/BaseLayout"; 4 4 import SectionList from "../../components/SectionList"; 5 5 import PageHeading from "../../components/PageHeading"; 6 - import { getSheetsCSV, parseCSV } from "../../lib/sheetsConnector"; 6 + import { importCSVDataAsJson } from "../../lib/sheetsConnector"; 7 7 8 8 export default class Recipes extends Component { 9 9 static async getInitialProps() { 10 - const recipesList = await importRecipes(); 10 + const recipesList = await importCSVDataAsJson( 11 + process.env.NEXT_PUBLIC_RECIPES_DATA_URL 12 + ); 11 13 12 14 return { recipesList }; 13 15 } ··· 38 40 ); 39 41 } 40 42 } 41 - 42 - const importRecipes = async () => { 43 - const recipesCsv = await getSheetsCSV( 44 - process.env.NEXT_PUBLIC_RECIPES_DATA_URL 45 - ); 46 - const recipesJson = parseCSV(recipesCsv); 47 - return recipesJson; 48 - };