krasimir / techy

A flat file CMS based on Gulp and AbsurdJS
http://krasimir.github.io/techy
MIT License
250 stars 23 forks source link

An ability to add images to preface #16

Closed zalun closed 10 years ago

zalun commented 10 years ago

I tried simply adding the tag, butthen it fails in tag pages. I could start path with /, but then it will not work on local machine. Maybe it would be good to start a server on localhost while techy is running?

krasimir commented 10 years ago

It's actually possible to solve the problem. The value of preface variable is used in a Techy command. This means that we could do whatever we need with the string before to send it to the page. So, if we have the following code in our markdown:

---
date: 11-01-2014
title: An article with code
preface: Curabitur consequat <img src="{siteURL}themes/default/public/img/favicon.png" /> ligula iaculis elit aliquet tincidunt. Proin aliquet massa venenatis, porta lorem.
tags:
  - javascript
  - nodejs
---

We ma replace the {siteURL} marker with the actual path:

var articles = this.pages('articles', 'date');
var html = '', to = max || articles.length;
for(var i=0; i<to; i++) {
    var article = articles[i];
    html += this.template(template, {
        title: article.get('title'),
        preface: article.get('preface').replace('{siteURL}', this.get('paths').root),
        link: this.linkto(article),
        date: article.get('date'),
        tags: article.get('tags').join(', ')
    });
}
krasimir commented 10 years ago

I should mention that a Techy command is run in the context of the current page. So, this.get('paths').root is pointing to the right place. Actually the value of this root property is different for every page and depends on its position based on the root project's directory.

P.S. let me know if the trick above works for you

zalun commented 10 years ago

Solved - yes I figured it out from the code - cool