<commit_before><!--
# File-Viewer
Copyright ©2016-2017 <NAME>

This is a contentless component - in effect it routes to other components
based on the filename (or specified file_type)

Note that something similar could just as easily be implemented using a component_map
binding, but for more complex heterogeneous collections, something like this could
implement a more sophisticated approach
-->
<div></div>
<script>
/* global data, b8r, container, component */
'use strict';

  const container = findOne('div');

  switch (data.file_type || data.url.split('.').pop()) {
    case 'md':
    case 'markdown':
      b8r.component('components/markdown-viewer').then(viewer => {
        b8r.insertComponent(viewer, container, data);
      });
      break;

    case 'html':
      if(data.url.match(/\.component\.html$/)) {
        data.url = data.url.substr(0, data.url.length - 15);
        b8r.component('components/component-viewer').then(viewer => {
          b8r.insertComponent(viewer, container, data);
        });
      } else {
        b8r.component('components/iframe').then(iframe => {
          b8r.insertComponent(iframe, container, data);
        });
      }
      break;

    case 'text':
      b8r.component('components/text-viewer').then(viewer => {
        b8r.insertComponent(viewer, container, data);
      });
      break;

    case 'js':
      b8r.component('components/literate-js-viewer').then(viewer => {
        b8r.insertComponent(viewer, container, data);
      });
      break;
  }
</script><commit_msg>fix — more robust<commit_after><!--
# File-Viewer
Copyright ©2016-2017 <NAME>

This is a contentless component - in effect it routes to other components
based on the filename (or specified file_type)

Note that something similar could just as easily be implemented using a component_map
binding, but for more complex heterogeneous collections, something like this could
implement a more sophisticated approach
-->
<style>
  .file-viewer-component > .iframe-component {
    height: 100%;
    width: 100%;
    padding: 0;
    margin: 0;
  }
</style>
<div></div>
<script>
/* global data, b8r, findOne */
'use strict';

  const container = findOne('div');

  switch (data.file_type || (data.url.match(/\.(\w+|component\.html)$/) || [])[1]) {
    case 'md':
    case 'markdown':
      b8r.component('markdown-viewer').then(viewer => {
        b8r.insertComponent(viewer, container, data);
      });
      break;

    case 'html':
      b8r.component('iframe').then(iframe => {
        b8r.insertComponent(iframe, container, {src: data.url});
      });
      break;

    case 'component.html':
      b8r.component('component-viewer').then(viewer => {
        data.url = data.url.match(/^(.*)\.component\.html$/)[1];
        b8r.insertComponent(viewer, container, data);
      });
      break;

    case 'text':
      b8r.component('text-viewer').then(viewer => {
        b8r.insertComponent(viewer, container, data);
      });
      break;

    case 'js':
      b8r.component('literate-js-viewer').then(viewer => {
        b8r.insertComponent(viewer, container, data);
      });
      break;

    default:
      console.error('unknown file type', data);
  }
</script>
{'fraction_non_alphanumeric': 0.14858934169278998, 'fraction_numerical': 0.01598746081504702, 'mean_word_length': 2.924969249692497, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2961385', 'n_tokens_mistral': 1016, 'n_tokens_neox': 962, 'n_words': 237}