Tumblr Builder
website·Indexed 29 days ago
http://yoriiis.github.io/tumblr-builderA JavaScript library for building custom Tumblr themes. It provides tools for customizing HTML for home pages, tagged pages, post pages, and various article types, along with a set of exposed instance methods for theme development.
What's inside Tumblr Builder
- TumblrBuilder is a framework that allows developers to build custom Tumblr themes using JavaScript. It provides a system for creating templates for the various page types and article types supported by the Tumblr platform.
TumblrBuilder core features and deployment options
TumblrBuilder includes several built-in features to enhance user experience and performance:
- Infinite scrolling on article lists
- Display of all article hashtags
- Related posts functionality
- Browser storage integration to improve load performance
Because it utilizes the Tumblr API, TumblrBuilder can be deployed either directly within a Tumblr blog or as part of a separate personal website.
Customize the Home page template
To customize the home page, provide a function totemplatesPages.home. This function receives an object containingtemplates(the post type template functions),tags(a list of all available hashtags), andposts(the initial list of articles to display). To enable infinite scrolling in your custom HTML, use thedata-infinite-scrollattribute on the posts container.function customHomePage({ templates, tags, posts }) { return ` <nav>...</nav> <div class="tags"> ${tags.map(tag => `<a href="#/tagged/${tag}">${tag}</a>`).join('')} </div> <div class="posts" data-infinite-scroll> ${posts.map(post => templates[post.type](post)).join('')} </div> `; } new TumblrBuilder({ templatesPages: { home: customHomePage } });Customize the Tagged page template
To customize the page that displays posts for a specific tag, provide a function totemplatesPages.tagged. The function receivestemplates(post type templates),tag(the current hashtag from the route), andposts(articles filtered by that hashtag). Use thedata-infinite-scrollattribute to support infinite scrolling.function customTaggedPage({ templates, tag, posts }) { return ` <h3>Tagged: ${tag}</h3> <div class="posts" data-infinite-scroll> ${posts.map(post => templates[post.type](post)).join('')} </div> `; } new TumblrBuilder({ templatesPages: { tagged: customTaggedPage } });Explore TumblrBuilder examples and playground
To learn how to use TumblrBuilder, you can use the following resources:
- Online Playground: An interactive environment available on CodePen.
- GitHub Repository: Download the source code to run examples locally. The
./examples/directory contains functional implementations including:basic-usage: Uses all default templates for pages and articles.custom-pages: Demonstrates custom templates for pages with default article templates.custom-posts: Demonstrates custom templates for articles with default page templates.
# Clone the repository to access examples git clone https://github.com/yoriiis/tumblr-builderDeploy the app to an external site
Because the application relies on the Tumblr API for all requests, it can be hosted on any external site using standard web hosting processes. It does not need to reside within the Tumblr ecosystem to function.Deploy the app to a Tumblr blog
To deploy the application directly to Tumblr, use the Tumblr customize page to import the custom HTML. You must host the associated asset files (scripts and styles) independently.- Copy the HTML content
- Open the Tumblr editor at
https://www.tumblr.com/customize/<hostname> - Paste the HTML content
- Host the asset files (scripts and styles)
- Navigate to the Tumblr blog
Customize TumblrBuilder themes
TumblrBuilder provides a minimalist default theme for all pages and article types. These default themes can be individually overridden to create custom designs.Customize the Post page template
To customize the individual post view, provide a function totemplatesPages.post. The function receivestemplates(post type templates),posts(data for the current article), andrelatedPosts(a list of related posts).function customPostPage({ templates, posts, relatedPosts }) { return ` <div class="post-content"> ${posts.map(post => templates[post.type](post)).join('')} </div> ${relatedPosts.length ? `<div class="related">${relatedPosts.map(p => templates[p.type](p)).join('')}</div>` : ''} `; } new TumblrBuilder({ templatesPages: { post: customPostPage } });Install tumblr-builder via npm
Install thetumblr-builderlibrary as a development dependency using npm or yarn.npm install tumblr-builder --save-devInitialize a TumblrBuilder application
To start a custom Tumblr blog, create a container element in your HTML and initialize theTumblrBuilderconstructor. After instantiation, call the.init()method to render the app.<!-- HTML Container --> <div id="tumblr-app"> <!-- App will be render here --> </div>
<script> const tumblr = new TumblrBuilder({ element: document.getElementById('tumblr-app'), host: "your-blog.tumblr.com", apiKey: "your-api-key" });
tumblr.init().then(response => { // App is rendered and ready }); </script>
Install TumblrBuilder via npm
Install thetumblr-builderpackage as a development dependency using npm.npm install tumblr-builder --save-dev