如何从模板获取Pelican版本号

时间:2018-11-18 17:52:52

标签: pelican

我想在HTML输出中添加元数据,以指示该页面是从Pelican生成的,并添加Pelican版本号。但是我找不到如何获得这个号码。我发现没有Pelican变量具有此信息。

调用可执行文件似乎是唯一的方法?

  for(j in 1:10){
    max_value[j] <- round(value * 1.1 ^ j, 2)
    min_value[j] <- round(value * 0.9 ^ j, 2)
    max_estimate[j] <- round(log(max_value[j]) + 0.2775, 3)
    min_estimate[j] <- round(log(min_value[j]) + 0.2775, 3)
  }

gg <- ggplot(data, aes(x = as.Date(rowname), y = get(ticker))) +
      geom_line() +
      # value calulation date vline
      geom_vline(xintercept = date_value, col = "Gray", size = 1) +
      # Index value at value calculation date hline
      geom_hline(yintercept = value_value, col = "Gray", size = 1) +
      # Max values hlines
      geom_hline(yintercept = pre_values_max, col = "Red", size = 1) +
      # value and return estimate for the value calculation date
      annotate("text", as.Date("2013-12-31"), value_value * 1.02,
               label = paste0(value, ", ", percent(return_estimate)), color = "Blue") +
      annotate("text", as.Date("2013-12-31"), pre_values_max[1] * 1.02,
               label = paste0(max_value[1], ", ", percent(max_estimate[1])), color = "Blue") +
      annotate("text", as.Date("2013-12-31"), pre_values_max[2] * 1.02 ^ 1,
               label = paste0(max_value[2], ", ", percent(max_estimate[2])), color = "Blue") +
      annotate("text", as.Date("2013-12-31"), pre_values_max[3] * 1.02,
               label = paste0(max_value[3], ", ", percent(max_estimate[3])), color = "Blue") +
      annotate("text", as.Date("2013-12-31"), pre_values_max[4] * 1.02,
               label = paste0(max_value[4], ", ", percent(max_estimate[4])), color = "Blue") +
      annotate("text", as.Date("2013-12-31"), pre_values_max[5] * 1.02,
               label = paste0(max_value[5], ", ", percent(max_estimate[5])), color = "Blue") +
      annotate("text", as.Date("2013-12-31"), pre_values_max[6] * 1.02,
               label = paste0(max_value[6], ", ", percent(max_estimate[6])), color = "Blue") +
      annotate("text", as.Date("2013-12-31"), pre_values_max[7] * 1.02 ^ 1,
               label = paste0(max_value[7], ", ", percent(max_estimate[7])), color = "Blue") +
      annotate("text", as.Date("2013-12-31"), pre_values_max[8] * 1.02,
               label = paste0(max_value[8], ", ", percent(max_estimate[8])), color = "Blue") +
      annotate("text", as.Date("2013-12-31"), pre_values_max[9] * 1.02,
               label = paste0(max_value[9], ", ", percent(max_estimate[9])), color = "Blue") +
      annotate("text", as.Date("2013-12-31"), pre_values_max[10] * 1.02,
               label = paste0(max_value[10], ", ", percent(max_estimate[10])), color = "Blue") +
      annotate("text", as.Date("2013-12-31"), pre_values_min[1] * 1.02,
               label = paste0(min_value[1], ", ", percent(min_estimate[1])), color = "Blue") +
      annotate("text", as.Date("2013-12-31"), pre_values_min[2] * 1.02,
               label = paste0(min_value[2], ", ", percent(min_estimate[2])), color = "Blue") +
      annotate("text", as.Date("2013-12-31"), pre_values_min[3] * 1.02,
               label = paste0(min_value[3], ", ", percent(min_estimate[3])), color = "Blue") +
      annotate("text", as.Date("2013-12-31"), pre_values_min[4] * 1.02,
               label = paste0(min_value[4], ", ", percent(min_estimate[4])), color = "Blue") +
      annotate("text", as.Date("2013-12-31"), pre_values_min[5] * 1.02,
               label = paste0(min_value[5], ", ", percent(min_estimate[5])), color = "Blue") +
      annotate("text", as.Date("2013-12-31"), pre_values_min[6] * 1.02,
               label = paste0(min_value[6], ", ", percent(min_estimate[6])), color = "Blue") +
      annotate("text", as.Date("2013-12-31"), pre_values_min[7] * 1.02,
               label = paste0(min_value[7], ", ", percent(min_estimate[7])), color = "Blue") +
      annotate("text", as.Date("2013-12-31"), pre_values_min[8] * 1.02,
               label = paste0(min_value[8], ", ", percent(min_estimate[8])), color = "Blue") +
      annotate("text", as.Date("2013-12-31"), pre_values_min[9] * 1.02,
               label = paste0(min_value[9], ", ", percent(min_estimate[9])), color = "Blue") +
      annotate("text", as.Date("2013-12-31"), pre_values_min[10] * 1.02,
               label = paste0(min_value[10], ", ", percent(min_estimate[10])), color = "Blue") +
      # Min values hlines
      geom_hline(yintercept = pre_values_min, col = "Green", size = 1) +
      ggtitle(paste0(country, ", ", ticker)) +
      xlab("Date") + ylab("Index")
    print(gg)

1 个答案:

答案 0 :(得分:2)

我不知道是否有更直接的方法来完成此操作,但是您可以在配置文件中添加以下代码(默认情况下为 pelicanconf.py ):

from pelican import __version__

PELICAN_VERSION = __version__

现在,您可以使用Jinja2语法在HTML模板中引用此新创建的变量,如下所示:

<p>I am using Pelican {{ PELICAN_VERSION }}.</p>

当您生成网站内容以获取包含静态文件的目录(默认情况下位于output/中)时,变量PELICAN_VERSION的内容将与您的其他变量一样添加配置文件,您应该一切顺利。