Introduction to Data-Driven Content in Jekyll
Jekyll is traditionally a static site generator, but its ability to consume data files allows you to inject dynamic content at build time. Using YAML, JSON, or CSV data files stored in the _data
directory, you can create templates that pull from structured data sources, greatly enhancing content maintainability and flexibility.
Why Use Data Files in Jekyll?
- Centralized Content Management: Manage repetitive or related content in a single file.
- Consistency: Avoid duplicate content entry by referencing a common data source.
- Scalability: Easily add or update items without touching template code.
- SEO Benefits: Structured data can improve semantic markup and search appearance.
Setting Up Data Files
Create a _data
folder in your Jekyll site root. Add YAML (.yml
), JSON (.json
), or CSV (.csv
) files. For example:
_data/products.yml
Example content for products.yml
:
- name: "SEO Audit Service" price: 299 features: - "Comprehensive site analysis" - "Competitor benchmarking" - "Actionable report" - name: "Content Marketing Package" price: 499 features: - "Monthly blog posts" - "Social media promotion" - "Monthly analytics"
Accessing Data in Templates
You can iterate over data entries with Liquid templating in your pages or includes:
{% raw %}
-
{% for product in site.data.products %}
-
{{ product.name }}
Price: ${{ product.price }}
-
{% for feature in product.features %}
- {{ feature }} {% endfor %}
{% endfor %}
Use Cases for Data-Driven Content
- Service or Product Listings: Centralize product info for easy updates.
- Team Member Profiles: Showcase bios and roles from a single YAML file.
- FAQs: Manage question-answer pairs efficiently.
- Pricing Tables: Generate tables dynamically without repetitive markup.
SEO Advantages of Data Files
When combined with proper semantic HTML, data-driven content can help search engines better understand your site structure and offerings. For instance, generating schema.org structured data dynamically improves rich snippet eligibility.
Example: Generating JSON-LD from Data
{% raw %} {% endraw %}
Best Practices
- Keep data files organized: Use descriptive filenames and folder structures.
- Validate data formats: Avoid errors by ensuring YAML/JSON syntax correctness.
- Use includes: Create reusable templates to render data uniformly.
- Version control: Keep data files under git to track changes.
Case Study: Dynamic Pricing Page
A SaaS startup built their pricing page entirely from YAML data files. This allowed marketing to update packages without developer intervention. The site maintained consistent design and SEO-friendly markup, reducing update time by 70%.
Conclusion
Leveraging data files in Jekyll enables content teams to manage large or repetitive content efficiently, while preserving SEO and design consistency. This data-driven approach is a powerful technique to scale static sites with dynamic flexibility.