Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
<head>
	<title>VuePress API Feed Reader</title>
  <!-- Google fonts -->
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700,900" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<!-- Ioincons -->
<link href="http://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet">
<!-- animate.css -->
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.4.0/animate.min.css">  
<!-- Import axios.js for mange http request in order to get remote API content -->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<!-- Vue starts here -->
    <div id="app">
      <div class="container" v-bind:class="hiContrast.class">
        <div class="wrap">
         <transition enter-active-class="animated pulse" leave-active-class="animated fadeOutUp"> 
         <header v-if="posts">
           <h1><i class="ion-ios-paper-outline"></i><span v-html="siteName"></span></h1>
          <button class="bttn" v-on:click="toggleHiContrast()"><i class="ion-contrast"></i> {{ hiContrast.label }}</button>
           <button v-if="posts" class="bttn" v-on:click="clearFeed()"><i class="ion-social-rss-outline"></i> Switch Feed</button>
        </header>
        </transition>
        <transition enter-active-class="animated fadeInLeft" leave-active-class="animated fadeOutLeft">
        <aside v-show="posts">
          <h2>Latest <input v-model="query.perPage" type="number" min="1" max="9"> News</h2>
          <ul class="article-list">
            <li v-for="post in posts" v-bind:class="{active: post.id == activePost.id}">
              <i class="ion-ios-arrow-right" v-if="post.id == activePost.id"></i>
              <a v-on:click="readPost(post)">
                <h6 v-html="post.title.rendered"></h6>
              </a>
            </li>
          </ul>
          <nav class="pagination">
            <button type="button" v-if='query.page > 1' v-on:click="wpQuery(query.page -= 1)" class="bttn nav-prev"><i class="ion-ios-arrow-left"></i>Newer</button>
            <div class="page-count">{{ query.page }} / {{ pageNumber }}</div>
            <button type="button" v-if='query.page != pageNumber' v-on:click="wpQuery(query.page += 1)" class="bttn nav-next">Older<i class="ion-ios-arrow-right"></i></button>
        </nav>
        </aside>
        </transition>
        <transition enter-active-class="animated fadeInRight" leave-active-class="animated fadeOut">
          <section v-if="activePost">
            <h1 v-html="activePost.title.rendered"></h1>
            <div class="entry-content" v-html="activePost.content.rendered"></div>
          </section>
        </transition>
      </div>
      <transition enter-active-class="animated fadeIn" leave-active-class="animated fadeOut">
        <div class="site-url" v-show="!posts">
          <button v-on:click="closeModal()"><i class="ion-close"></i></button>
          <h2>WordPress Website's URL</h2>
          <input type="text" v-model="query.url" v-on:keyup.enter="searchFeed()">
          <h6>{{ queryError }}</h6>
        </div>
      </transition>
    </div>
  </div>
</html>
              
            
!

CSS

              
                $black: #333333;
$white: #ffffff;

h1, h2, h3, h4, h5, h6 {margin: 14px 0; font-weight: 700;}

h1 {font-size: 38px;}
h2 {font-size: 32px;}
h3 {font-size: 28px;}
h4 {font-size: 22px;}
h5 {font-size: 18px;}
h6 {font-size: 16px;}

p {font-size: 18px; font-weight: 300;}

a {
  color: $black;
  &:hover {
    color: #aaa;
  }
}

strong { font-weight: 700; }
em { font-style: italic; }

.bttn {
  background: transparent;
  color: $black;
  border: 2px solid $black;
  border-radius: 25px;
  padding: 10px 20px;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  &:hover {
    background: $black;
    color: $white;
  }
}

input {
  border: 3px solid;
  padding: 12px 16px;
  border-radius: 20px;
  width: 300px;
  color: $black;
  font-weight: 700;
  box-sizing: border-box;
  background: transparent;
}

.container {
  background: $white;
  color: $black;
  font-family: 'Montserrat', sans-serif;
  overflow: auto;
  overflow-x: hidden;
  .wrap {
    max-width: 1140px;
    margin: 0 auto;
  }
}

.container.hi-contrast {
  background: $black;
  color: $white;
  a {
    color: $white;
    &:hover {
      color: #aaa;
    }
  }
  .bttn {
    color: $white;
    background: transparent;
    border-color: $white;
    &:hover {
      background: $white;
      color: $black;
    }
  }
  input {
    color: $white;
    border-color: $white;
  }
}

header {
  padding: 10px 0;
  border-bottom: 3px solid;
  h1 {
    display: inline-block;
    font-size: 34px;
    i {
      margin-right: 14px;
    }
  }
  button {
    float: right;
    margin: 14px 0 0 40px;
    vertical-align: text-bottom;
  }
}

section {
  display: inline-block;
  max-width: 75%;
  float: left;
  padding: 20px 60px;
  box-sizing: border-box;
  .entry-content {
    line-height: 1.4;
    p { margin: 0 0 14px; }
    a { font-weight: 400; }
    table { width: 100%; }
    td {
      font-weight: 300;
      border: 1px solid;
      padding: 10px;
    }
    th {
      font-weight: 700;
    }
    ul {
      padding: 10px 0 20px 40px;
      list-style-type: disc;
    }
    iframe {
      max-width: 100%;
    }
    img {
      max-width: 100%;
      height: auto;
    }
    .alignleft {
      float: left;
      margin: 5px 15px 5px 0px;
    }
    .alignright {
      float: right;
      margin: 5px 0px 5px 15px;
    }
    .aligncenter {
      text-align: center;
      margin: 10px auto;
      display: block;
    }
    .gallery {
      margin: 20px 0;
    }
    .gallery-item {
        display: inline-block;
        margin: 4px;
    }
  }
}

aside {
  max-width: 25%;
  display: inline-block;
  float: left;
  box-sizing: border-box;
  border-right: 3px solid;
  h2 {
    padding: 0 10px 14px;
    border-bottom: 3px dashed;
    font-size: 24px;
    i {
      margin-right: 8px;
      margin-left: 0px
    }
    input {
      max-width: 60px;
      padding: 8px 12px;
      line-height: 1;
      font-size: 22px;
      font-weight: 900;
      border: 2px solid;
    }
  }
  h6 { font-size: 16px;
    font-weight: 400;
  }
  ul {
    padding: 0 0 0 10px;
    li {
      padding-right: 10px;
      list-style: none;
      border-bottom: 2px dashed #ededed;
      line-height: 1.4;
      &.active a h6 {
        font-weight: 900;
      }
      a {
        text-decoration: none;
        cursor: pointer;
      }
      i {
        display: inline-block;
        float: left;
        margin-left: -16px;
      }
    }
  }
  .pagination {
    width: 100%;
    max-width: 240px;
    margin: 20px auto;
    text-align: center;
    display: block;
    overflow: auto;
    .page-count {
      display: inline-block;
      font-weight: 400;
      margin: 0 auto;
      line-height: 1.8;
    }
    .nav-next { 
      float: right;
      i { margin-left: 10px; }
    }
    .nav-prev { 
      float: left;
      i { margin-right: 10px; }
    }
    .bttn {
      font-size: 12px;
      padding: 6px 10px;
      border: none;
      font-weight: 400;
      border-radius: 4px;
    }
  }
}

.site-url {
  height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  text-align: center;
  align-items: center;
  justify-content: center;
  position: relative;
  h2 {
    font-size: 42px;
    margin: 10px 20px 12px 5px;
    min-width: 400px;
    width: 100%;
    text-align: left;
    margin-left: 28%;
  }
  h6 {
    color: #aaa;
    margin: 10px 0 0 14px;
    min-width: 400px;
    width: 100%;
    text-align: left;
    margin-left: 26%;
  }
  button {
    position: absolute;
    top: 40px;
    right: 0;
    font-size: 38px;
    border: none;
    background: none;
    cursor: pointer;
  }
  input {
    display: block;
    min-width: 400px;
    width: 75%;
    font-size: 24px;
    padding: 10px 40px;
    font-weight: 300;
    border-radius: 10px;
    transition: all 250ms ease-in-out;
    &:focus {
      box-shadow: 2px 4px 10px rgba(0,0,0,0.2);
    }
  }
}
              
            
!

JS

              
                var app = new Vue({
  el: '#app', //start vue here
  data: {
    query: {
      url: 'https://europe.wordcamp.org/2020',
      perPage: 5,
      page: 1,
    },
    oldQuery: '',
    siteName: 'WP API Feed Reader',
    pageNumber: '',
    posts: '',
    activePost: '',
    queryError: '',
    hiContrast: {
      class: '',
      label: 'dark'
    }
  },
  mounted: function() {
      this.wpQuery();
      this.getSiteName();
  },
  methods: {
    toggleHiContrast: function () {
      if(this.hiContrast.class) {
        this.hiContrast.class = '';
        this.hiContrast.label = 'dark';
      } else {
        this.hiContrast.class = 'hi-contrast';
        this.hiContrast.label = 'light';
      }
    },
    readPost: function(post) {
      this.activePost = post;
      window.scrollTo(0, 0);
    },
    getSiteName: function(url  = this.query.url) {
      
      axios.get( this.query.url + '/wp-json/' )
      .then(response => {
        this.siteName = response.data.name
       })
    },
    wpQuery: function(page = this.query.page, perPage = this.query.perPage, url = this.query.url) {
      var route = url + '/wp-json/wp/v2/posts?per_page=' + perPage + '&page=' + page;
      //GET posts from WordPress REST API
      axios.get( route, { timeout: 2500, maxRedirects: 3 } )
      .then(response => {
          this.posts = response.data,
          this.pageNumber = response.headers['x-wp-totalpages'],
          this.activePost = (this.posts[0]),
          this.oldQuery = url;
      })
      .catch(error => {
        if(!error.status) {
          this.queryError = 'No REST API Founded';
        }
      });
      window.scrollTo(0, 0);
    },
    searchFeed: function() {
      var regEx = /^(http:\/\/|https:\/\/)+?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/gm;
      var url = this.query.url;
      
      if(url.match(regEx)){
        this.wpQuery(1, this.query.perPage, url);
        this.getSiteName(url);
      } else { this.queryError = 'Requires a valid URL with protocol (e.g. https://wptavern.com)'; }
    },
    clearFeed: function() {
      this.posts = '';
      this.activePost = '';
      this.query.url = '';
      this.siteName = 'WP API Feed Reader';
    },
    closeModal: function() {
      this.query.url = this.oldQuery;
      this.wpQuery();
    }
  },
  watch: {
    "query.perPage": function(pp) {
      if(pp < 10 && pp > 0){
        this.wpQuery(1, pp);
        this.query.page = 1;
      }
    }
  }
});
              
            
!
999px

Console