Skip to content

Instantly share code, notes, and snippets.

View tonyspiro's full-sized avatar
🚀
Building and shipping

Tony Spiro tonyspiro

🚀
Building and shipping
View GitHub Profile
// index.js
const api = require('cosmicjs')();
const bucket = api.bucket({
slug: 'simple-react-blog',
read_key: '' // Find this in Bucket > Settings > API Access after logging in https://app.cosmicjs.com/login
})
export async function getStaticProps() {
const post = (await bucket.getObject({
slug: 'a-wonderful-blog-post-about-earth'
})).object
// Get Object by Metafield Object ID
const run = async () => {
const Cosmic = require('cosmicjs')
const api = Cosmic()
const bucket = api.bucket({
slug: 'cosmic-js'
})
const data = await bucket.getObjects({
type: 'articles',
limit: 20,
@tonyspiro
tonyspiro / posts-with-props.json
Created September 3, 2019 16:56
posts-with-props.json
{
"objects": [
{
"slug": "a-wonderful-blog-post-about-earth",
"title": "A Wonderful Blog Post About Earth",
"content": "<p>When I orbited the Earth in a spaceship, I saw for the first time how beautiful our planet is. Mankind, let us preserve and increase this beauty, and not destroy it!</p><p>Space, the final frontier. These are the voyages of the Starship Enterprise. Its five-year mission: to explore strange new worlds, to seek out new life and new civilizations, to boldly go where no man has gone before.</p><p>If you could see the earth illuminated when you were in a place as dark as night, it would look to you more splendid than the moon.</p><p>To be the first to enter the cosmos, to engage, single-handed, in an unprecedented duel with nature&mdash;could one dream of anything more?</p><p>We choose to go to the moon in this decade and do the other things, not because they are easy, but because they are hard, because that goal will serve to organize and measure the best of our energi
@tonyspiro
tonyspiro / posts-without-props.json
Created September 3, 2019 16:55
posts-without-props.json
{
"objects": [
{
"_id": "59df6dd5fd8d731b21001191",
"bucket": "59df6dcbfd8d731b21001188",
"slug": "a-wonderful-blog-post-about-earth",
"title": "A Wonderful Blog Post About Earth",
"content": "<p>When I orbited the Earth in a spaceship, I saw for the first time how beautiful our planet is. Mankind, let us preserve and increase this beauty, and not destroy it!</p><p>Space, the final frontier. These are the voyages of the Starship Enterprise. Its five-year mission: to explore strange new worlds, to seek out new life and new civilizations, to boldly go where no man has gone before.</p><p>If you could see the earth illuminated when you were in a place as dark as night, it would look to you more splendid than the moon.</p><p>To be the first to enter the cosmos, to engage, single-handed, in an unprecedented duel with nature&mdash;could one dream of anything more?</p><p>We choose to go to the moon in this decade and do the other things, not because they are easy, but because they
@tonyspiro
tonyspiro / index.js
Last active August 23, 2019 17:10
Upload Media to Your Cosmic JS Bucket using Multer
// index.js
const fs = require('fs')
const Cosmic = require('cosmicjs')()
const multer = require('multer')
const express = require('express')
var app = express()
const bucket = Cosmic.bucket({
slug: 'your-bucket-slug',
write_key: ''
})
<video id="myVideo" controls></video>
<!-- Use HLS.js to support the HLS format in browsers. -->
<script src="https://cdn.jsdelivr.net/npm/hls.js@0.8.2"></script>
<script>
(function(){
// Replace with your asset's playback ID
var playbackId = "oIdQlddn3YGhfCK00Mkj0169KMArk2s701Q";
var url = "https://stream.mux.com/"+playbackId+".m3u8";
module.exports = {
siteMetadata: {
title: 'Cosmic JS Gatsby Starter Localization',
nav: [
{ slug: '', name: 'Home' },
{ slug: 'about', name: 'About' },
{ slug: 'contact', name: 'Contact' },
{ slug: 'not-found', name: 'Not Found' },
],
languages: [
@tonyspiro
tonyspiro / index.html
Last active October 7, 2018 17:27
JSON Metafield
<script src="https://unpkg.com/cosmicjs@3.0.1/cosmicjs.browser.min.js"></script>
<script>
var api = new Cosmic();
var bucket = api.bucket({
slug: 'json-bucket'
})
bucket.addObject({
title: 'Test Page',
type_slug: 'pages',
metafields: [
@tonyspiro
tonyspiro / default.js
Last active September 10, 2018 18:30
import React from 'react'
import Router from 'next/router'
import bucket from '../config'
import Page from '../components/page'
import PageNotFound from '../components/404'
import Header from '../components/header'
import Footer from '../components/footer'
import Nav from '../components/nav'
class DefaultPage extends React.Component {
static async getInitialProps({ req, query }) {
# Install Cosmic CLI
npm i -g cosmic-cli

# Login to your Cosmic JS account
cosmic login

# Installs example content to a new or existing Bucket and downloads the app locally
cosmic init node-starter
cd node-starter