Giter VIP home page Giter VIP logo

Comments (5)

AprilSylph avatar AprilSylph commented on August 25, 2024 3

The first four in this array have the correct ID to be able to build a link to the post, but the others do not work

This is because of Javascript being unable to handle newer, 64-bit post IDs as numbers. See how the larger IDs always end in 00; the precision is being lost. Cyle's prototype was made 2 years ago, before the switchover to larger post IDs. To account for it, you'll need to initialise posts as a regular Object and stop using {PostId} as a number:

<script>
-    var posts = new Array();
+    var posts = new Object();
</script>
{block:Posts}
<script>
-    posts[{PostId}] = {NPF};
+    posts['{PostId}'] = {NPF};
</script>
{/block:Posts}
<div id="post-list"></div>

and to pull more data from the theme engine than content, layout, and trail, I feel like the easiest way would to just set the data in the same breath:

<script>
    posts['{PostId}'] = {NPF};
+   posts['{PostId}'].tags = [ {block:Tags}'{Tag}',{/block:Tags} ];
</script>

although personally, i would have posts still be an Array of Objects and use {PostId} as a property rather than an identifier. Cyle using custom identifiers on an Array is... questionable.

from docs.

AprilSylph avatar AprilSylph commented on August 25, 2024 2

(FWIW, I have a full JSON-powered theme here, but it's designed for just visualising posts as JSON rather than using the JSON to do anything. I do recommend looking at it though, since putting regular theme variables into JavaScript is tricky.)

from docs.

cyle avatar cyle commented on August 25, 2024 2

☝️ Everything April said is what I would've told ya, too. 😄

More documentation on the different theme "blocks" available (i.e. {Tag}) is here.

although personally, i would have posts still be an Array of Objects and use {PostId} as a property rather than an identifier

I would advise this as well. My prototype in the gist you linked was very rough and quickly made to prove a point, not really something ready for actual usage. I'll try to make that clearer in the gist.

from docs.

AprilSylph avatar AprilSylph commented on August 25, 2024 1

You need to construct the post object yourself. {NPF} only contains content, layout, and trail. Everything else needs to be pulled from the theme engine rather than the API to prevent distributing your (or anyone else's) API key.

from docs.

lharby avatar lharby commented on August 25, 2024

Thank you so much for this. So that I don't keep pestering you, is there documentation somewhere about all the properties the post object will return? If I want likes, reblogs and other meta data?

This does not mention tags for example:
https://github.com/tumblr/docs/blob/master/npf-spec.md

from docs.

Related Issues (20)

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.