Skip to content

Instantly share code, notes, and snippets.

🚀
Building and shipping

Tony Spiro tonyspiro

🚀
Building and shipping
Block or report user

Report or block tonyspiro

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View index.js
// 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,
View 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
View 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 Aug 23, 2019
Upload Media to Your Cosmic JS Bucket using Multer
View index.js
// 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: ''
})
View mux.html
<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";
View gatsby-config.js
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 Oct 7, 2018
JSON Metafield
View index.html
<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: [
View default.js
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 }) {
View node-starter.md
# 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
View serverless-starter.md
# 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 serverless-starter
cd serverless-starter
You can’t perform that action at this time.