Skip to content

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricdelpoux committed Aug 21, 2020
0 parents commit 4a9ece4
Show file tree
Hide file tree
Showing 32 changed files with 17,309 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2

[*.md]
indent_size = 4
trim_trailing_whitespace = false
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
env: {
node: true,
},
parserOptions: {
ecmaVersion: 2019,
},
extends: ["eslint:recommended", "prettier"],
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
*.log
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"bracketSpacing": false,
"semi": false,
"trailingComma": "es5"
}
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 2.0.0

- Updated: Source code rewrited from scratch
- Updated: Option `albums` renamed to `albumsTitles`
- Added: `albumsRegex` option
- Added: `albumsUpdate` option
- Added: `photosMaxWidth` option
- Added: `photosMaxHeight` option
- Added: `photosCrop` option
- Added: `debug` option
- Added: `gatsby-source-google-photos-token` script for token generation
- Added: `gatsby-image` compatibility
- Deleted: `clientId` option
- Deleted: `clientSecret` option

# 1.0.0

The v1 was coded and publish by @tinavanschelt
You can find the old repository [here](https://github.com/tinavanschelt/gatsby-source-google-photos)
Thank you to her to let me make a new version of this plugin
82 changes: 82 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# gatsby-source-google-photos

[![npm package][npm-badge]][npm]

`gatsby-source-google-photos` is a [Gatsby](https://www.gatsbyjs.org/) plugin to use [Google Photos](https://photos.google.com/) as a data source.

Why use [Google Photos](https://photos.google.com/) to store your photos:

- 💸 Free
- 🔒 Secured
- 🛢 Unlimited space
- 🖥 Desktop web app
- 📱 Mobile app
- 🖍 In-app photos edition
- 💾 Automatic backup from your phone
- 🌈 `gatsby-image` compatible

## Usage

1. Download `gatsby-source-google-photos` from the NPM registry:

```shell
yarn add gatsby-source-google-photos gatsby-transformer-sharp gatsby-plugin-sharp
```

2. Open a terminal at the root of your project and [Generate a token](./docs/token.md)

```shell
gatsby-source-google-photos-token
```

3. [Add the plugin](./docs/options.md) in your `gatsby-config.js` file

```js
module.exports = {
plugins: [
{
resolve: "gatsby-source-google-photos",
options: {
albumsTitles: ["TITLE_A", "TITLE_B"],
},
},
"gatsby-transformer-sharp",
"gatsby-plugin-sharp",
}
],
}
```

4. [Query your photos](./docs/queries.md)

## Showcase

You are using `gatsby-source-google-photos` for your website?
Thank you!

Please add your website to the [Showcase](./showcase.yml)

## Documentation

- [Token](./docs/token.md)
- [Options](./docs/options.md)
- [Create pages](./docs/pages.md)
- [FAQ](./docs/faq.md)

## Contributing

- ⇄ Pull/Merge requests and ★ Stars are always welcome.
- For bugs and feature requests, please [create an issue][github-issue].

## Changelog

See [CHANGELOG](./CHANGELOG.md)

## License

This project is licensed under the MIT License - see the
[LICENCE](./LICENCE.md) file for details

[npm-badge]: https://img.shields.io/npm/v/gatsby-source-google-photos.svg?style=flat-square
[npm]: https://www.npmjs.org/package/gatsby-source-google-photos
[github-issue]: https://github.com/cedricdelpoux/gatsby-source-google-photos/issues/new
42 changes: 42 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Options

```js
module.exports = {
plugins: [
{
resolve: "gatsby-source-google-photos",
options: {
albumsTitles: ["TITLE_A", "TITLE_B"],
//---
// All the following options are OPTIONAL
//---
//
// Slower but easier to use.
// It will make `albumsTitles` options useless
// You need to rename your `GooglePhotos albums first
albumsRegex: /^mygatsbysite.com/,
//
// Useful to add some metadata
// eg: Rename your `GooglePhotos` albums: "mygatsbysite.com/travel/country"
albumsUpdate: (album) => {
const [, category, country] = album.title.split("/")
return {
...album,
category,
country,
}
},
//
// Download smaller or bigger photos
photosMaxWidth: 512,
photosMaxHeight: 512,
photosCrop: true,
//
// For a better stack trace and more information
// Useful when you open a issue to report a bug
debug: true,
},
},
],
}
```
84 changes: 84 additions & 0 deletions docs/queries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Queries

## Query photos

```js
import React from "react"
import Img from "gatsby-image"
import {graphql} from "gatsby"

export default ({data: {allGooglePhotosPhoto}}) => {
return allGooglePhotosPhoto.nodes.map((photoNode) => (
<div style={{width: 500}}>
<Img fluid={photoNode.photo.childImageSharp.fluid} />
</div>
))
}

export const pageQuery = graphql`
query {
allGooglePhotosPhoto {
nodes {
photo {
childImageSharp {
fluid(maxWidth: 500, quality: 100) {
...GatsbyImageSharpFluid
}
}
}
}
}
}
`
```

## Query albums

```js
import React from "react"
import Img from "gatsby-image"
import {graphql} from "gatsby"

export default ({data: {allGooglePhotosAlbum}}) => {
return allGooglePhotosAlbum.nodes.map((albumNode) => (
<>
<h2>{albumNode.title}</h2>
<div style={{width: 500}}>
<Img fluid={albumNode.cover.childImageSharp.fluid} />
</div>
<div>{"Photos:"}</div>
{albumNode.photos.map((photoNode) => (
<div style={{width: 500}}>
<Img fluid={photoNode.photo.childImageSharp.fluid} />
</div>
))}
</>
))
}

export const pageQuery = graphql`
query {
allGooglePhotosAlbum {
nodes {
title
cover {
childImageSharp {
fluid(maxWidth: 500, quality: 100) {
...GatsbyImageSharpFluid
}
}
}
photos {
photo {
childImageSharp {
fluid(maxWidth: 500, quality: 100) {
...GatsbyImageSharpFluid
}
}
}
}
}
}
}
`
```
37 changes: 37 additions & 0 deletions docs/token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Token

Token must be provided with an environment variable: `process.env.GATSBY_SOURCE_GOOGLE_DOCS_TOKEN`.

`gatsby-source-google-docs` provides a command-line script to generate a Google token.

> You must be in the root folder of your project to run the script
```shell
gatsby-source-google-docs-token
```

Follow the instructions and the token will be added to your different `.env` files with the format: `GATSBY_SOURCE_GOOGLE_DOCS_TOKEN={...}`

> If you have multiple `.env` files for your different environments, the script will write the token at the end of each file
You should add your `.env` files to your `.gitignore` because it contains some sensitive informations.

# Troubleshooting

## `'gatsby-source-google-docs-token' is not recognized as an internal or external command,`

Add an `npm` script to your `package.json`:

```
"scripts": {
"token": "gatsby-source-google-docs-token"
}
```

Then generate a token:

```
yarn token
# or
npm run token
```
20 changes: 20 additions & 0 deletions example/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
env: {
es6: true,
node: true,
},
parserOptions: {
sourceType: "module",
ecmaVersion: 2019,
},
extends: ["eslint:recommended", "plugin:react/recommended", "prettier"],
settings: {
react: {
version: "16.12",
},
},
rules: {
"react/prop-types": "off",
"react/display-name": "off",
},
}
69 changes: 69 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# dotenv environment variable files
.env*

# gatsby files
.cache/
public

# Mac files
.DS_Store

# Yarn
yarn-error.log
.pnp/
.pnp.js
# Yarn Integrity file
.yarn-integrity
5 changes: 5 additions & 0 deletions example/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"bracketSpacing": false,
"semi": false,
"trailingComma": "es5"
}
Loading

0 comments on commit 4a9ece4

Please sign in to comment.