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

getContent() does not process Blade files #172

Open
imsus opened this issue Nov 14, 2017 · 3 comments
Open

getContent() does not process Blade files #172

imsus opened this issue Nov 14, 2017 · 3 comments

Comments

@imsus
Copy link

imsus commented Nov 14, 2017

Currently the $page->getContent() function only allows markdown files to be rendered.

Why?

I've got a content like this:

---
extends:
  web: _layouts.post
  amp: _layouts.amp
  feed: _partials.feed-item
title: My First Blog Post
date: 2017-03-23
section: content
---

This post is *profoundly* interesting.

@include('_partials.image', ['src' => 'https://source.unsplash.com/random', 'alt' => ''])

If you curious about what does the _partials.image.blade.php does, it just switching between img tag and amp-img tag for amp-html templates.

@switch($page->_meta->extending)
    @case('instant-articles')
        <figure data-feedback="fb:likes, fb:comments">
          <img src="{{ $src }}" alt="{{ $alt }}">
          @if($caption ?? false)
            <figcaption>
              <h1>{{ $caption }}</h1>
            </figcaption>
          @endif
        </figure>
        @break
    @case('amp')
        <figure>
          <amp-img src="{{ $src }}" alt="{{ $alt }}"></amp-img>
          @if($caption ?? false)
            <figcaption>Caption</figcaption>
          @endif
        </figure>
        @break
    @default
      <figure>
        <img src="{{ $src }}" alt="{{ $alt }}">
        @if($caption ?? false)
          <figcaption>Caption</figcaption>
        @endif
      </figure>
@endswitch

Problems

The problem arise when I want to output the article into feed. When I use $page->getContent(), it doesn't render the blade directive.

feed.blade.json

{
  "user_comment": "This is a JSON Feed. A modern alternative of RSS.",
  "version": "https://jsonfeed.org/version/1",
  "title": "{{ $page->blogTitle }} Feed",
  "home_page_url": "{{ $page->baseUrl }}",
  "feed_url": "{{ $page->getUrl() }}",
  "items": {!! $posts->map(function($item) {
    return [
      'id' => $item->getUrl('web'),
      'content_html' => $item->getContent()
    ];
  })->values() !!}
}

Leaving the code like this:

feed.json

{
  "user_comment": "This is a JSON Feed. A modern alternative of RSS.",
  "version": "https://jsonfeed.org/version/1",
  "title": "Imam Susanto Blog Feed",
  "home_page_url": "http://localhost:3000",
  "feed_url": "http://localhost:3000/feed.json",
  "items": [
    {
      "id": "http://localhost:3000/blog/my-first-blog-post",
      "content_html":
        "<p>This post is <em>profoundly</em> interesting.</p>\n<p>@include('_partials.image', ['src' =&gt; '<a href=\"https://source.unsplash.com/random\">https://source.unsplash.com/random</a>', 'alt' =&gt; ''])</p>"
    },
    {
      "id": "http://localhost:3000/blog/my-second-blog-post",
      "content_html":
        "<p>This post is <em>profoundly</em> interesting.</p>\n<p>@include('_partials.image', ['src' =&gt; '<a href=\"https://source.unsplash.com/random\">https://source.unsplash.com/random</a>', 'alt' =&gt; ''])</p>"
    }
  ]
}

Is it possible that blade files also included? So that files like post.blade.json or post.blade.xml will get the same treatment.

Thank you for reading this issue. Hope it helps.

@damiani
Copy link
Contributor

damiani commented Nov 15, 2017

There is a conceptual issue and a practical issue that make this complicated:

  1. Unlike Markdown files, a Blade file can technically include multiple @sections, in which case it's not entirely clear what getContent() should return. Realistically, I think we should return the first section in those cases.
  2. Practically, we need to figure out a way to extract the first @section content from the Blade file, including any parsed content (such as @includes, as in your example).

I'm going to take a look at this on Friday to see if I can come up with a solution.

@imsus
Copy link
Author

imsus commented Nov 15, 2017

Thank you @damiani for your reply. I see the situation.

Maybe we can create a special blade directive for Jigsaw that will be the output of getContent(). This directive will have special parsing such as:

  • Smartypants
  • Other markdown renderer
  • Blade Include / Component.
  • Or we can extend with other plugins as well via parameter.

For this example, I named the new directive @export

---
extends:
  web: _layouts.post
  amp: _layouts.amp
  feed: _partials.feed-item
title: My First Blog Post
date: 2017-03-23
---
@export('content', ['smartypants', 'markdown-plus', 'parse-include'])
    This post is *profoundly* interesting.

    @include('_partials.image', ['src' => 'https://source.unsplash.com/random', 'alt' => ''])
@endexport

Hope it helps.

@damiani damiani changed the title getContent() does not process Blade files [In Progress] getContent() does not process Blade files Oct 2, 2018
@damiani damiani changed the title [In Progress] getContent() does not process Blade files getContent() does not process Blade files Oct 2, 2018
@breakdancingcat
Copy link

Any updates?

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

No branches or pull requests

4 participants