Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for Dashboard #329

Closed
wants to merge 4 commits into from
Closed

API for Dashboard #329

wants to merge 4 commits into from

Conversation

ashmaroli
Copy link
Member

Proposing an API for the dashboard.
The API outputs a modified version the current site's site-wide payload:

  • remove file contents from data files, posts, pages, collections.
  • sort the pages by recent edits
{
  "content": null,
  "jekyll": {
    "version": "3.4.2",
    "environment": "development"
  },
  "highlighter_prefix": null,
  "highlighter_suffix": null,
  "site": {
    "time": "2017-03-19 14:18:53 -0400",
    "tags": {},
    "pages": [
      "page.md",
      "page-dir/test/page2.md",
      "page-dir/page1.md",
      "assets/style.scss",
      "assets/app.coffee"
    ],
    "posts": [
      "2016-01-01-test-post.md",
      "test/2016-01-02-test2.md",
      "2016-02-01-test-post-2.md",
      "2016-03-01-test-post-3.md",
      "more posts/2016-04-01-post-within-subdirectory.md",
      "more posts/some more posts/2016-05-01-a-test-post-within-subdirectory.md",
      "more posts/some more posts/2016-05-02-another-test-post-within-subdirectory.md"
    ],
    "static_files": [
      "#<Jekyll::StaticFile:0x3cf4860>",
      "#<Jekyll::StaticFile:0x3cf47d0>",
      "#<Jekyll::StaticFile:0x3cf46e0>",
      "#<Jekyll::StaticFile:0x3cf4638>"
    ],
    "categories": {},
    "collections": [
      "posts",
      "puppies"
    ],
    "html_pages": [
      "page.md",
      "page1.md",
      "page2.md"
    ],
    "source": "[--redacted--]/spec/fixtures/site",
    "destination": "[--redacted--]/spec/fixtures/site/_site",
    "plugins_dir": "_plugins",
    "layouts_dir": "_layouts",
    "data_dir": "_data",
    "includes_dir": "_includes",
    "safe": false,
    "include": [
      ".htaccess"
    ],
    "exclude": [
      "Gemfile",
      "Gemfile.lock",
      "README.md"
    ],
    "keep_files": [
      ".git",
      ".svn"
    ],
    "encoding": "utf-8",
    "markdown_ext": "markdown,mkdown,mkdn,mkd,md",
    "show_drafts": null,
    "limit_posts": 0,
    "future": false,
    "unpublished": false,
    "whitelist": [],
    "gems": [
      "jekyll-admin"
    ],
    "markdown": "kramdown",
    "highlighter": "rouge",
    "lsi": false,
    "excerpt_separator": "\n\n",
    "incremental": false,
    "detach": false,
    "port": "4000",
    "host": "127.0.0.1",
    "baseurl": "",
    "show_dir_listing": false,
    "permalink": "date",
    "paginate_path": "/page:num",
    "timezone": null,
    "quiet": false,
    "verbose": true,
    "defaults": [
      {
        "scope": {
          "path": ""
        },
        "values": {
          "some_front_matter": "default"
        }
      }
    ],
    "liquid": {
      "error_mode": "warn"
    },
    "rdiscount": {
      "extensions": []
    },
    "redcarpet": {
      "extensions": []
    },
    "kramdown": {
      "auto_ids": true,
      "toc_levels": "1..6",
      "entity_output": "as_char",
      "smart_quotes": "lsquo,rsquo,ldquo,rdquo",
      "input": "GFM",
      "hard_wrap": false,
      "footnote_nr": 1,
      "syntax_highlighter": "rouge",
      "syntax_highlighter_opts": {},
      "coderay": {}
    },
    "title": "Your awesome title",
    "foo": "bar",
    "watch": true,
    "serving": true,
    "url": "http://localhost:4000",
    "related_posts": null,
    "data_files": [
      "data_file.yml",
      "template-config.yml"
    ]
  },
  "layout": null,
  "page": null,
  "paginator": null
}

@benbalter
Copy link
Contributor

@ashmaroli can you explain a bit more about what's going on here? It looks like you're aggregating many existing endpoints into a single call?

@ashmaroli
Copy link
Member Author

It looks like you're aggregating many existing endpoints into a single call

With this call, the current site's entire payload gets streamed in to the API after being stripped off any content data. Except for appearing to be similar to existing endpoints, this cumulative call is a different object.

We can either use this goldmine of data or further strip to make things leaner.

@benbalter
Copy link
Contributor

Except for appearing to be similar to existing endpoints, this cumulative call is a different object.

Why do we need a different object here? Is there data in this endpoint not exposed in those other endpoints? Can we expose that data via the existing endpoints? Can we accomplish the same user experience with multiple calls? My concern here is that we're creating a purpose-build endpoint for a single view when the data is already exposed in subject-specific (and generalized endpoints).

@ashmaroli
Copy link
Member Author

relevant data (IMO) not exposed via existing endpoints:

{
  "content": null,
+  "jekyll": {
+    "version": "3.4.2",
+    "environment": "development"
+  },
  "highlighter_prefix": null,
  "highlighter_suffix": null,
  "site": {
    "time": "2017-03-19 14:18:53 -0400",
    "tags": {},
    "pages": [
      "page.md",
      "page-dir/test/page2.md",
      "page-dir/page1.md",
      "assets/style.scss",
      "assets/app.coffee"
    ],
    "posts": [
      "2016-01-01-test-post.md",
      "test/2016-01-02-test2.md",
      "2016-02-01-test-post-2.md",
      "2016-03-01-test-post-3.md",
      "more posts/2016-04-01-post-within-subdirectory.md",
      "more posts/some more posts/2016-05-01-a-test-post-within-subdirectory.md",
      "more posts/some more posts/2016-05-02-another-test-post-within-subdirectory.md"
    ],
    "static_files": [
      "#<Jekyll::StaticFile:0x3cf4860>",
      "#<Jekyll::StaticFile:0x3cf47d0>",
      "#<Jekyll::StaticFile:0x3cf46e0>",
      "#<Jekyll::StaticFile:0x3cf4638>"
    ],
    "categories": {},
    "collections": [
      "posts",
      "puppies"
    ],
    "html_pages": [
      "page.md",
      "page1.md",
      "page2.md"
    ],
    "source": "[--redacted--]/spec/fixtures/site",
    "destination": "[--redacted--]/spec/fixtures/site/_site",
    "plugins_dir": "_plugins",
    "layouts_dir": "_layouts",
    "data_dir": "_data",
    "includes_dir": "_includes",
    "safe": false,
    "include": [
      ".htaccess"
    ],
    "exclude": [
      "Gemfile",
      "Gemfile.lock",
      "README.md"
    ],
    "keep_files": [
      ".git",
      ".svn"
    ],
    "encoding": "utf-8",
    "markdown_ext": "markdown,mkdown,mkdn,mkd,md",
    "show_drafts": null,
    "limit_posts": 0,
    "future": false,
    "unpublished": false,
    "whitelist": [],
    "gems": [
      "jekyll-admin"
    ],
    "markdown": "kramdown",
    "highlighter": "rouge",
    "lsi": false,
    "excerpt_separator": "\n\n",
    "incremental": false,
    "detach": false,
    "port": "4000",
    "host": "127.0.0.1",
    "baseurl": "",
    "show_dir_listing": false,
    "permalink": "date",
    "paginate_path": "/page:num",
    "timezone": null,
    "quiet": false,
    "verbose": true,
    "defaults": [
      {
        "scope": {
          "path": ""
        },
        "values": {
          "some_front_matter": "default"
        }
      }
    ],
    "liquid": {
      "error_mode": "warn"
    },
    "rdiscount": {
      "extensions": []
    },
    "redcarpet": {
      "extensions": []
    },
    "kramdown": {
      "auto_ids": true,
      "toc_levels": "1..6",
      "entity_output": "as_char",
      "smart_quotes": "lsquo,rsquo,ldquo,rdquo",
      "input": "GFM",
      "hard_wrap": false,
      "footnote_nr": 1,
      "syntax_highlighter": "rouge",
      "syntax_highlighter_opts": {},
      "coderay": {}
    },
    "title": "Your awesome title",
    "foo": "bar",
+    "watch": true,
    "serving": true,
    "url": "http://localhost:4000",
    "related_posts": null,
    "data_files": [
      "data_file.yml",
      "template-config.yml"
    ]
  },
  "layout": null,
  "page": null,
  "paginator": null
}

the above data also exposes the entire site.config hash that includes data defined by Jekyll::Configuration::DEFAULTS which is not exposed via Configuration API

Can we accomplish the same user experience with multiple calls?

I'm sorry, I don't have the stats to comment on this. The data files, html_pages, pages and posts objects in the data above are trimmed versions of existing API calls

@benbalter
Copy link
Contributor

Nice. Thanks @ashmaroli. Since #320 watch should be disabled in all cases, but would a version or meta endpoint for the version and environment make sense?

@ashmaroli
Copy link
Member Author

ashmaroli commented Mar 20, 2017

Since #320 watch should be disabled in all cases, but would a version or meta endpoint for the version and environment make sense?

yes, watch should be disabled, yet the data returned shows its set to true. Need to investigate further.
I think Jekyll version on the dashboard makes sense: The user need not refer their Gemfile.lock to see which version of Jekyll is currently in use. environment: is not relevant as of now.

@ashmaroli
Copy link
Member Author

a point in favor of outputting jekyll environment value via this API:

  • JekyllAdmin works locally both with default JEKYLL_ENV and with the variable set to any arbitrary value via JEKYLL_ENV=. So having the dashboard display this to the user is a good thing, especially when Jekyll.logger doesn't output this value to the user, as of this writing.

@ashmaroli
Copy link
Member Author

watch returned true above owing to the --watch switch passed via script/test-server. I've added a commit to output this as false at all times.

@ashmaroli
Copy link
Member Author

Any feedback here @mertkahyaoglu ?

@mertkahyaoglu
Copy link
Member

If @benbalter also approves, we can merge this.

@benbalter
Copy link
Contributor

@ashmaroli see my questions above

Why do we need a different object here? Is there data in this endpoint not exposed in those other endpoints? Can we expose that data via the existing endpoints? Can we accomplish the same user experience with multiple calls? My concern here is that we're creating a purpose-build endpoint for a single view when the data is already exposed in subject-specific (and generalized endpoints).

In my mind, the API should be modeled after the data, not the presentation. If there's data in this endpoint not exposed elsewhere, let's expose it where it makes sense, but I'm less inclined to add (and support) and new endpoint to support a specific view, especially when making additional local network calls are so cheap.

@ashmaroli
Copy link
Member Author

@benbalter Thank you for the feedback.

the API should be modeled after the data, not the presentation

Excellent diagnosis. You caught me! 😃

If there's data in this endpoint not exposed elsewhere, let's expose it where it makes sense,

sounds reasonable 👍
Hmm... that leaves me with just.. data related to Jekyll Drop.. 😒

@ashmaroli ashmaroli closed this Apr 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants