• Stars
    star
    1,137
  • Rank 40,702 (Top 0.9 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A collaborative documentation site, powered by Google Docs.

Library Supported node versions Tests

A collaborative newsroom documentation site, powered by Google Docs.

Table of Contents

Demo Site & User Guide

Documentation about how to get started with Library is hosted as a working (read only) demo on Heroku. Consult the site for more detailed instructions than this readme about how to get the most out of Library: https://nyt-library-demo.herokuapp.com.

Contacting us

Love Library? Let us know by joining our Google Group and dropping us a line. You'll also stay up to date with the latest Library features via our release notes, which get sent to this list.

Community

Here are some of the organizations using Library so far.

Marketplace

The New York Times

Northwestern University Knight Lab

Star Tribune

WBEZ

The Los Angeles Times Data and Graphics Department

Contributing

See CONTRIBUTING.md for information on how to contribute code and/or documentation on GitHub or on the demo site.

Questions

If you have questions about how to get your copy of Library up and running, join our Google Group, and let us know what you're running into. We also keep an eye on the #proj-library channel in the News Nerdery Slack. We'll do our best to answer your questions.

Development Workflow

  1. Clone and cd into the repo:

    git clone [email protected]:nytimes/library.git && cd library

  2. From the Google API console, create or select a project, then create a service account with the Cloud Datastore User role. It should have API access to Drive and Cloud Datastore. Store these credentials in server/.auth.json.

    • To use oAuth, you will also need to create oAuth credentials.
    • To use the Cloud Datastore API for reading history, you will need to add in your GCP_PROJECT_ID.
  3. Install dependencies:

    npm install --no-optional

  4. Create a .env file at the project root. An example .env might look like

# node environment (development or production)
NODE_ENV=development
# Google oAuth credentials
GOOGLE_CLIENT_ID=123456-abcdefg.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=abcxyz12345
GCP_PROJECT_ID=library-demo-1234
# comma separated list of approved access domains or email addresses (regex is supported).
APPROVED_DOMAINS="nytimes.com,dailypennsylvanian.com,(.*)?ar.org,[email protected]"
SESSION_SECRET=supersecretvalue

# Google drive Configuration
# team or folder ("folder" if using a folder instead of a team drive)
DRIVE_TYPE=team
# the ID of your team's drive or shared folder. The string of random numbers and letters at the end of your team drive or folder url.
DRIVE_ID=0123456ABCDEF

Make sure to not put any comments in the same line as DRIVE_TYPE and DRIVE_ID vars.

Ensure you share your base drive or folder with the email address associated with the service account created in step 2.

Be careful! Setting NODE_ENV to development changes the built in behaviors for site authentication to allow accounts other than those in the APPROVED_DOMAINS list. Never use NODE_ENV=development for your deployed site, only locally.

  1. Start the app:

    npm run watch

The app should now be running at localhost:3000. Note that Library requires Node v8 or higher.

Tests

You can run functional and unit tests, which test HTML parsing and routing logic, with npm test. A coverage report can be generated by running npm run test:cover.

The HTML parsing tests are based on the Supported Formats doc. To download a fresh copy of the HTML after making edits, run node test/utils/updateSupportedFormats.js.

Customization

Styles, text, caching logic, and middleware can be customized to match the branding of your organization. This is covered in the customization readme.

A sample customization repo is provided at nytimes/library-customization-example.

Deploying the app

Wherever you deploy Library, you'll likely want to set up a Google service account and OAuth 2.0 client Set up your service account with API access to Drive and Cloud Datastore.

If you wish to deploy Library with customizations, create a git repo with the files you would like to include. Set the CUSTOMIZATION_GIT_REPO environment variable to the cloning URL. Files in the repo and packages specified in the package.json will be included in your library installation.

For more detailed instructions, consult the Getting Started section of the demo site: https://nyt-library-demo.herokuapp.com/get-started

Using Heroku

This button can quickly deploy to Heroku: Deploy

Set your app's GOOGLE_APPLICATION_JSON, GOOGLE_CLIENT_ID, and GOOGLE_CLIENT_SECRET with values from the service account and Oauth client. Add <your-heroku-app-url>.com as an authorized domain in the general OAuth consent screen setup and then add http://<your-heroku-app-url>.com/auth/redirect as the callback url in the OAuth credential setup itself.

Using Google App Engine

You can also deploy Library to GAE, using the included app.yaml. Note that you will need to enable billing on your GCP project in order to use Google App Engine. More detailed instructions are provided on the demo site.

Using Docker Dockerhub

Library can be used as a base image for deployment using Docker. This allows you to automate building and deploying a custom version of Library during Docker's build phase. If you create a repo with the contents of your custom folder, you could deploy library from that repo with a Dockerfile like the following:

FROM nytimes/library

# copy custom files to library's custom repo
COPY . ./custom/

# move to a temporary folder install custom npm packages
WORKDIR /usr/src/tmp
COPY package*.json .npmrc ./
RUN npm i
# copy node modules required by custom node modules
RUN yes | cp -rf ./node_modules/* /usr/src/app/node_modules

# return to app directory and build
WORKDIR /usr/src/app
RUN npm run build

# start app
CMD [ "npm", "start" ]

Standard Deployment

Library is a standard node app, so it can be deployed just about anywhere. If you are looking to deploy to a standard VPS, Digital Ocean's tutorials are a great resource.

App structure

Server

The main entry point to the app is index.js.

This file contains the express server which will respond to requests for docs in the configured team drive or shared folder. Additionally, it contains logic about issuing 404s and selecting the template to use based on the path.

Views

Views (layouts) are located in the layouts folder. They use the .ejs extension, which uses a syntax similar to underscore templates.

Base styles for the views are in the styles directory containing Sass files. These files are compiled to CSS and placed in public/css.

Doc parsing

Doc HTML fetch and parsing is handled by docs.js. fetchDoc takes the ID of a Google doc and a callback, then passes the HTML of the document into the callback once it has been downloaded and processed.

Listing the drive

Traversing the contents of the NYT Docs folder is handled by list.js. There are two exported functions:

  • getTree is an async call that returns a nested hash (tree) of Google Drive Folder IDs mapped to their children. It is used by the server to determine whether a route is valid or not.

  • getMeta synchronously returns a hash of Google Doc IDs to metadata objects that were saved in the course of populating the tree. This metadata includes edit history, document authors, and parent folders.

The tree and file metadata are repopulated into memory on an interval (currently 60s). Calling getTree multiple times will not return fresher data.

Auth

Authentication with the Google Drive v3 api is handled by the auth.js file, which exposes a single method getAuth. getAuth will either return an already instantiated authentication client or produce a fresh one. Calling getAuth multiple times will not produce a new authentication client if the credentials have expired; we should build this into the auth.js file later to automatically refresh the credentials on some sort of interval to prevent them from expiring.

User Authentication

Library currently supports both Slack and Google Oauth methods. As Library sites are usually intended to be internal to a set of limited users, Oauth with your organization is strongly encouraged. To use Slack Oauth, specify your Oauth strategy in your .env file, like so:

# Slack needs to be capitalized as per the Passport.js slack oauth docs http://www.passportjs.org/packages/passport-slack-oauth2/
OAUTH_STRATEGY=Slack

You will need to provide Slack credentials, which you can do by creating a Library Oauth app in your Slack workspace. After creating the app, save the app's CLIENT_ID and CLIENT_SECRET in your .env file:

SLACK_CLIENT_ID=1234567890abcdefg
SLACK_CLIENT_SECRET=09876544321qwerty

You will need to add a callback URL to your Slack app to allow Slack to redirect back to your Library instance after the user is authenticated.

More Repositories

1

covid-19-data

A repository of data on coronavirus cases and deaths in the U.S.
6,992
star
2

objective-c-style-guide

The Objective-C Style Guide used by The New York Times
5,848
star
3

gizmo

A Microservice Toolkit from The New York Times
Go
3,753
star
4

Store

Android Library for Async Data Loading and Caching
Java
3,531
star
5

NYTPhotoViewer

A modern photo viewing experience for iOS.
Objective-C
2,847
star
6

pourover

A library for simple, fast filtering and sorting of large collections in the browser. There is a community-maintained fork that addresses a handful of post-NYT issues available via @hhsnopek's https://github.com/hhsnopek/pourover
JavaScript
2,393
star
7

kyt

Starting a new JS app? Build, test and run advanced apps with kyt πŸ”₯
JavaScript
1,922
star
8

react-tracking

🎯 Declarative tracking for React apps.
JavaScript
1,876
star
9

ice

track changes with javascript
JavaScript
1,708
star
10

backbone.stickit

Backbone data binding, model binding plugin. The real logic-less templates.
JavaScript
1,641
star
11

openapi2proto

A tool for generating Protobuf v3 schemas and gRPC service definitions from OpenAPI specifications
Go
940
star
12

gziphandler

Go middleware to gzip HTTP responses
Go
857
star
13

svg-crowbar

Extracts an SVG node and accompanying styles from an HTML document and allows you to download it all as an SVG file.
JavaScript
840
star
14

ingredient-phrase-tagger

Extract structured data from ingredient phrases using conditional random fields
Python
784
star
15

Emphasis

Dynamic Deep-Linking and Highlighting
JavaScript
576
star
16

tamper

Ruby
499
star
17

three-loader-3dtiles

This is a Three.js loader module for handling OGC 3D Tiles, created by Cesium. It currently supports the two main formats, Batched 3D Model (b3dm) - based on glTF Point cloud.
TypeScript
444
star
18

react-prosemirror

A library for safely integrating ProseMirror and React.
TypeScript
418
star
19

rd-blender-docker

A collection of Docker containers for running Blender headless or distributed ✨
Python
415
star
20

Register

Android Library and App for testing Play Store billing
Kotlin
381
star
21

text-balancer

Eliminate typographic widows and other type crimes with this javascript module
JavaScript
373
star
22

document-viewer

The NYTimes Document Viewer
JavaScript
310
star
23

ios-360-videos

NYT360Video plays 360-degree video streamed from an AVPlayer on iOS.
Objective-C
273
star
24

three-story-controls

A three.js camera toolkit for creating interactive 3d stories
TypeScript
247
star
25

backbone.trackit

Manage unsaved changes in a Backbone Model.
JavaScript
202
star
26

aframe-loader-3dtiles-component

A-Frame component using 3D-Tiles
JavaScript
187
star
27

marvin

A go-kit HTTP server for the App Engine Standard Environment
Go
177
star
28

drone-gke

Drone plugin for deploying containers to Google Kubernetes Engine (GKE)
Go
165
star
29

Chronicler

A better way to write your release notes.
JavaScript
162
star
30

nginx-vod-module-docker

Docker image for nginx with Kaltura's VoD module used by The New York Times
Dockerfile
161
star
31

collectd-rabbitmq

A collected plugin, written in python, to collect statistics from RabbitMQ.
Python
143
star
32

public_api_specs

The API Specs (in OpenAPI/Swagger) for the APIs available from developer.nytimes.com
136
star
33

gunsales

Statistical analysis of monthly background checks of gun purchases
R
130
star
34

gcp-vault

A client for securely retrieving secrets from Vault in Google Cloud infrastructure
Go
119
star
35

rd-bundler-3d-plugins

Bundler plugins for optimizing glTF 3D models
JavaScript
119
star
36

Fech

Deprecated. Please see https://github.com/dwillis/Fech for a maintained fork.
Ruby
115
star
37

data-training

Files from the NYT data training program, available for public use.
114
star
38

drone-gae

Drone plugin for managing deployments and services on Google App Engine (GAE)
Go
97
star
39

mock-ec2-metadata

Go
95
star
40

encoding-wrapper

Collection of Go wrappers for Video encoding cloud providers (moved to @video-dev)
Go
85
star
41

redux-taxi

πŸš• Component-driven asynchronous SSR in isomorphic Redux apps
JavaScript
70
star
42

video-captions-api

Agnostic API to generate captions for media assets across different transcription services.
Go
61
star
43

lifeline

A cron-based alternative to running daemons
Ruby
58
star
44

gcs-helper

Tool for proxying and mapping HTTP requests to Google Cloud Storage (GCS).
Go
54
star
45

logrotate

Go
54
star
46

httptest

A simple concurrent HTTP testing tool
Go
48
star
47

kyt-starter-universal

Deprecated, see: https://github.com/NYTimes/kyt/tree/master/packages/kyt-starter-universal
JavaScript
33
star
48

nytcampfin

A thin Python client for The New York Times Campaign Finance API
Python
27
star
49

safejson

safeJSON provides replacements for the 'load' and 'loads' methods in the standard Python 'json' module.
Python
27
star
50

thumbor-docker-image

Docker image for Thumbor smart imaging service
26
star
51

times_wire

A thin Ruby client for The New York Times Newswire API
Ruby
26
star
52

haiti-debt

Historical data on Haiti’s debt payments to France collected by The New York Times.
21
star
53

jsonlogic

Clojure
20
star
54

elemental-live-client

JS library to communicate with Elemental live API.
JavaScript
19
star
55

Open-Source-Science-Fair

The New York Times Open Source Science Fair
JavaScript
19
star
56

tweetftp

Ruby Implementation of the Tweet File Transfer Protocol (APRIL FOOLS JOKE)
Ruby
19
star
57

hhs-child-migrant-data

Data from the U.S. Department of Human Health and Services on children who have migrated to the United States without an adult.
19
star
58

prosemirror-change-tracking-prototype

JavaScript
18
star
59

plumbook

Data from the Plum Book, published by the GPO every 4 years
17
star
60

libvmod-queryfilter

Simple querystring filter/sort module for Varnish Cache v3-v6
M4
16
star
61

sneeze

Python
16
star
62

querqy-clj

Search Query Rewriting for Elasticsearch and more! Built on Querqy.
Clojure
14
star
63

sqliface

handy interfaces and test implementations for Go's database/sql package
Go
14
star
64

grocery

The grocery package provides easy mechanisms for storing, loading, and updating Go structs in Redis.
Go
13
star
65

oak-byo-react-prosemirror-redux

JavaScript
13
star
66

vase.elasticsearch

Vase Bindings for Elasticsearch
Clojure
11
star
67

library-customization-example

An example repo that customizes Library behavior
SCSS
11
star
68

counter

count things, either as a one-off or aggregated over time
Ruby
11
star
69

kyt-starter

The default starter-kyt for kyt apps.
JavaScript
10
star
70

open-blog-projects

A repository for code examples that are paired with our Open Blog posts
Swift
9
star
71

rd-mobile-pg-demos

HTML
9
star
72

tulsa-1921-data

Data files associated with our story on the 1921 race massacre in Tulsa, Oklahoma.
9
star
73

pocket_change

Python
9
star
74

mentorship

7
star
75

sort_by_str

SQL-like sorts on your Enumerables
Ruby
7
star
76

drone-gdm

Drone.io plugin to facilitate the use of Google Deployment Manager in drone deploy phase.
Go
6
star
77

kyt-starter-static

Deprecated, see: https://github.com/NYTimes/kyt/tree/master/packages/kyt-starter-static
JavaScript
6
star
78

s3yum

Python
5
star
79

pocket

Python
5
star
80

drone-openapi

A Drone plugin for publishing Open API service specifications
Go
5
star
81

threeplay

Go client for the 3Play API.
Go
4
star
82

amara

Amara client for Go
Go
4
star
83

go-compare-expressions

Go
3
star
84

kaichu

Python
3
star
85

license

NYT Apache 2.0 license
3
star
86

prosemirror-tooltip

JavaScript
2
star
87

photon-dev_demo

A "Sustainable Systems, Powered By Python" Demo Repository (1 of 3)
Shell
2
star
88

std-cat

Content Aggregation Technology β€” a standard for content aggregation on the Web
HTML
1
star