title: Automatically place an include in Jekyll post
body: <p>I'm trying to build a post layout which automatically places an <code>include</code> based on the criteria below:</p>
  
  <ol>
  <li>If the post contains an <code>&lt;h3&gt;</code>, place the include right <strong>before</strong> it.</li>
  <li>Otherwise, place the include <strong>after</strong> the second paragraph.</li>
  </ol>
  
  <p>I've been trying this for a while now, but am unable to find the right way to do it.</p>
  
  <pre><code>&lt;section class="post-content"&gt;
    {{ content }}
  &lt;/section&gt;
  </code></pre>
  
  <p>And let's say, the content is:</p>
  
  <pre><code>&lt;p&gt;Elit amet reprehenderit velit non dolor officia do in ea laborum do sunt. Est voluptate non cupidatat aliquip aliqua aliqua esse id consequat. Ullamco labore aliqua ad Lorem laborum occaecat et occaecat sunt esse esse est eiusmod aliqua.&lt;/p&gt;
  &lt;p&gt;Ex duis dolor laboris dolor mollit id irure ullamco aliquip commodo ut mollit. Deserunt officia amet consectetur pariatur qui esse ut cupidatat eu consequat eu eiusmod. Veniam ipsum culpa esse nostrud consequat ipsum consectetur eu veniam magna commodo laborum labore eiusmod do.&lt;/p&gt;
  &lt;p&gt;Reprehenderit aute commodo voluptate nostrud elit exercitation anim nisi nisi culpa eu qui tempor laboris commodo ut quis.&lt;/p&gt;
  </code></pre>
  
  <p>I want this to become:</p>
  
  <pre><code>&lt;p&gt;Elit amet reprehenderit velit non dolor officia do in ea laborum do sunt. Est voluptate non cupidatat aliquip aliqua aliqua esse id consequat. Ullamco labore aliqua ad Lorem laborum occaecat et occaecat sunt esse esse est eiusmod aliqua.&lt;/p&gt;
  &lt;p&gt;Ex duis dolor laboris dolor mollit id irure ullamco aliquip commodo ut mollit. Deserunt officia amet consectetur pariatur qui esse ut cupidatat eu consequat eu eiusmod. Veniam ipsum culpa esse nostrud consequat ipsum consectetur eu veniam magna commodo laborum labore eiusmod do.&lt;/p&gt;
  
  {% include image.html %}
  
  &lt;p&gt;Reprehenderit aute commodo voluptate nostrud elit exercitation anim nisi nisi culpa eu qui tempor laboris commodo ut quis.&lt;/p&gt;
  </code></pre>
  
  <p><code>image.html</code> just contains code to pick up the image from Instagram in case the post has Instagram code, else, pick the image from the repository. Like so:</p>
  
  <pre><code>{% if page.instagram %}
    &lt;div class="insta-div"&gt;
      &lt;img src="https://www.instagram.com/p/{{ page.instagram }}/media?size=l" alt="Cover: {{ page.title }}" /&gt;
      &lt;form action="https://instagram.com/{{ site.instagram }}" target="_blank"&gt;
        &lt;button class="insta-follow" type="submit"&gt;
          &lt;i class="icon-instagram"&gt;&lt;/i&gt; Follow
        &lt;/button&gt;
      &lt;/form&gt;
    &lt;/div&gt;
  {% elsif page.image %}
    &lt;img src="{{ page.image | prepend: site.baseurl | prepend: site.url }}" alt="Cover: {{ page.title }}" /&gt;
  {% else %}
  {% endif %}
  </code></pre>
  
  <p>I tried with <code>replace_first</code> and <code>split</code> and all, but I'm probably not doing it right. Could someone please help me with this?</p>
  
  <p>Thank you!</p>