Giter VIP home page Giter VIP logo

sanity-plugin-order-documents's Introduction

sanity-plugin-order-documents

Order your Sanity documents via drag-and-drop.

sanity-plugin-order-documents example

Installation

To install the plugin, navigate to the root directory of your Sanity Studio project and run:

sanity install order-documents

Then, open sanity.json and append "order-documents" to the "plugins" array:

"plugins": [
  "order-documents"
],

Now, when you run sanity start, you should see the "Order Documents" tab in the top navigation bar.

Usage

To save a custom order, you'll need to add a hidden order field inside the schema file of any document type you want to order.

For example, to add order to the "movie" type, go into ./schemas/movie.js and add:

fields: [
  // other fields,
  {
    name: "order",
    title: "Order",
    type: "number",
    hidden: true,
  },
],

Now, when we query our dataset, we can order the results according to the order property.

For example, to query movies using Sanity's query language GROQ, we can write:

*[_type == "movie"] | order(order asc)

Our custom order has been saved, and it will be reflected in the result!

Development

To develop this plugin, clone it into a local directory. Then, navigate to the root of the cloned repository and run:

yarn
yarn link
yarn start

Next, navigate to a Sanity Studio project and run:

yarn link "sanity-plugin-order-documents"

Open sanity.json in the Sanity Studio project and append "order-documents" to the "plugins" array:

"plugins": [
  "order-documents"
],

We're already watching our plugin for changes, so all that's left is to run our Sanity Studio with sanity start.

Limitations

Right now, this plugin can be used to order the 100 most recently edited documents of a particular type. If you'd like to help add support for larger collections, consider contributing!

Contributing

I'd welcome any contributions, from fixing a typo to something more substantial. You can raise a PR in the project's GitHub repository.

sanity-plugin-order-documents's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.