function get_amp_markup()

in webserver/article.php [130:161]


function get_amp_markup($instant_article, $url, $rules) {
  $cache_key = $rules . $url;

  $possible_amp_markup = try_get_cached_value($cache_key, CACHE_KEY_TYPE_AMP);

  // Cache hit
  if (!is_null($possible_amp_markup))
    return $possible_amp_markup;

  // Cache miss
  $properties = array(
    'styles-folder' => __DIR__.'/styles/' // Where the styles are stored
  );

  $amp_article = AMPArticle::create($instant_article, $properties);
  $amp_article->getObserver()->addFilter(
    'AMP_HEAD',
    function ($head) {
      $style_node = $head->ownerDocument->createElement('link');
      $style_node->setAttribute('rel', 'stylesheet');
      $style_node->setAttribute('href', 'style.css');
      $head->appendChild($style_node);
      return $head;
    }
  );

  $amp_markup = $amp_article->render();

  try_set_cached_value($cache_key, $amp_markup, CACHE_KEY_TYPE_AMP);

  return $amp_markup;
}