Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A collaborative documentation site, powered by Google Docs.

License

NotificationsYou must be signed in to change notification settings

nytimes/library

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 byjoining 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

SeeCONTRIBUTING.md for information on how to contribute code and/or documentation on GitHub or on thedemo 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 andcd into the repo:

    git clone git@github.com: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 inserver/.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 yourGCP_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 credentialsGOOGLE_CLIENT_ID=123456-abcdefg.apps.googleusercontent.comGOOGLE_CLIENT_SECRET=abcxyz12345GCP_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,demo.user@demo.site.edu"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 asDRIVE_TYPE andDRIVE_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 todevelopment 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 atlocalhost:3000. Note that Library requires Node v8 or higher.

Tests

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

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

Customization

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

A sample customization repo is provided atnytimes/library-customization-example.

Deploying the app

Wherever you deploy Library, you'll likely want toset up a Google service account andOAuth 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 theCUSTOMIZATION_GIT_REPO environment variable to the cloning URL. Files in the repo and packages specified in thepackage.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'sGOOGLE_APPLICATION_JSON,GOOGLE_CLIENT_ID, andGOOGLE_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 addhttp://<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 includedapp.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 thedemo site.

Using DockerDockerhub

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

FROM nytimes/library# copy custom files to library's custom repoCOPY . ./custom/# move to a temporary folder install custom npm packagesWORKDIR /usr/src/tmpCOPY package*.json .npmrc ./RUN npm i# copy node modules required by custom node modulesRUN yes | cp -rf ./node_modules/* /usr/src/app/node_modules# return to app directory and buildWORKDIR /usr/src/appRUN npm run build# start appCMD ["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 isindex.js.

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

Views

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

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

Doc parsing

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

Listing the drive

Traversing the contents of the NYT Docs folder is handled bylist.js. Thereare two exported functions:

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

  • getMeta synchronously returns a hash of Google Doc IDs to metadata objectsthat were saved in the course of populating the tree. This metadata includesedit 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 methodgetAuth.getAuth will either return an already instantiated authentication client or produce a fresh one. CallinggetAuth 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'sCLIENT_ID andCLIENT_SECRET in your.env file:

SLACK_CLIENT_ID=1234567890abcdefgSLACK_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.


[8]ページ先頭

©2009-2025 Movatter.jp