Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown parser #2

Merged
merged 9 commits into from
Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(posts):make posts json contain yaml style fm
- add theme file for syntax highlighting
- start building better app structure
  • Loading branch information
Jason Hodges committed Aug 22, 2017
commit f9236f4dd906b5ba3ae6ea550f5b945581444c15
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ jspm_packages
.node_repl_history


/dist
/dist
.idea
6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

7 changes: 0 additions & 7 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/ngx-blog.iml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/typescript-compiler.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

4 changes: 0 additions & 4 deletions .idea/watcherTasks.xml

This file was deleted.

867 changes: 0 additions & 867 deletions .idea/workspace.xml

This file was deleted.

68 changes: 45 additions & 23 deletions config/dir-parse.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,56 @@
// https://code-maven.com/list-content-of-directory-with-nodejs
var fs = require('fs');
var path = require('path');
var jsonfile = require('jsonfile');
var postsjson = 'src/assets/_posts/posts.json';
var dir = 'src/assets/_posts';
// https://github.com/jxson/front-matter <- consider for yaml front matter parsing
const fs = require('fs');
const fm = require('front-matter');
const path = require('path');
const jsonfile = require('jsonfile');
const postsjson = 'src/assets/_posts/posts.json';
const dir = 'src/assets/_posts';

// if (process.argv.length <= 2) {
// console.log("Usage: " + __filename + " path/to/directory");
// process.exit(-1);
// }
var extFilter = 'md';
// var pathSupplied = process.argv[2];
var pathSupplied = dir;
const extFilter = 'md';
const pathSupplied = dir;

function extension(element) {
var extName = path.extname(element);
const extName = path.extname(element);
return extName === '.' + extFilter;
};
}

fs.readdir(pathSupplied, function(err, items) {
var opener = '{ "posts": ';
var closer = ' }';
var posts = items.filter(extension).map((item) => {
var file = pathSupplied + '/' + item;
var obj = { title: file };
return obj;
})
/**
* cycle through directory for files
*/
fs.readdir(pathSupplied, function (err, items) {
let opener = '{ "posts": ';
let closer = ' }';
let posts = [];
let file = '';
let fileContent = '';
let content = '';
let body = '';
let attributes = {};
let title = '';
let description = '';
/**
* cycle over items, filtering for files matching extension
* @type {Array}
*/
posts = items.filter(extension).map((item) => {
file = pathSupplied + '/' + item;
fileContent = fs.readFileSync(file, 'utf8');
content = fm(fileContent);
console.log('*** content ***\n', content);
body = content.body;
attributes = content.attributes;
title = attributes.title;
description = attributes.description;

return {
file: file,
title: title,
description: description
};
});

opener += JSON.stringify(posts);
opener += closer;
console.log("Posts: ", JSON.stringify(posts));
fs.writeFile(postsjson, opener);
});
23 changes: 0 additions & 23 deletions config/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,6 @@ module.exports = {
exclude: /node_modules/,
loaders: ['raw-loader', 'sass-loader']
},
// {
// test: /\.scss$/,
// use: extractSass.extract({
// use: [{
// loader: 'css-loader'
// }, {
// loader: 'sass-loader'
// }],
// fallback: 'style-loader'
// })
// },
// {
// test: /\.css$/,
// exclude: helpers.root('src', 'app'),
// loader: ExtractTextPlugin.extract({
// fallbackLoader: 'style-loader',
// loader: 'css-loader?sourceMap'
// })
// },
{
test: /\.css$/,
include: helpers.root('src', 'app'),
Expand Down Expand Up @@ -91,10 +72,6 @@ module.exports = {

new WebpackShellPlugin({
onBuildStart: ['node ./config/dir-parse.js']
}),

new LoopMarkdownPlugin({
name: 'My Awesome Loop Markdown Plugin'
})

]
Expand Down
6 changes: 0 additions & 6 deletions config/webpack.dev.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
const webpack = require('webpack');
const helpers = require('./helpers');
const times = require('lodash/times');
const webpackMerge = require('webpack-merge');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const WebpackShellPlugin = require('webpack-shell-plugin');
const commonConfig = require('./webpack.common.js');


module.exports = webpackMerge(commonConfig, {
devtool: 'cheap-module-eval-source-map',

Expand All @@ -16,13 +12,11 @@ module.exports = webpackMerge(commonConfig, {
filename: '[name].js',
chunkFilename: '[id].chunk.js'
},

plugins: [
new WebpackShellPlugin({
onBuildStart: ['node ./config/dir-parse.js']
})
],

devServer: {
historyApiFallback: true,
stats: 'minimal'
Expand Down
1 change: 0 additions & 1 deletion config/webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const commonConfig = require('./webpack.common.js');


const ENV = process.env.NODE_ENV = process.env.ENV = 'production';

module.exports = webpackMerge(commonConfig, {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@angular/upgrade": "~4.3.1",
"angular-in-memory-web-api": "~0.3.2",
"core-js": "^2.4.1",
"front-matter": "^2.1.2",
"highlightjs": "^9.10.0",
"jsonfile": "^3.0.1",
"marked": "^0.3.6",
Expand Down
2 changes: 1 addition & 1 deletion src/app/app-routing.module.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/app/app-routing.module.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HomeComponent } from '../home/home.component';
import { HomeComponent } from './ngx-blog/containers/home/home.component';
import { RouterModule, Routes } from '@angular/router';
import {NgModule} from '@angular/core';

Expand Down
Empty file removed src/app/app.component.scss
Empty file.
15 changes: 6 additions & 9 deletions src/app/app.module.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/app/app.module.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 6 additions & 9 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
import { PostsService } from '../services/posts.service';
import { HomeComponent } from '../home/home.component';
import { AppRoutingModule } from './app-routing.module';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from '@angular/http';
import { MarkdownToHtmlModule } from 'ng2-markdown-to-html';

import { AppComponent } from './app.component';
import { NgxBlogModule } from './ngx-blog/ngx-blog.module';
import { CommonModule } from '@angular/common';

@NgModule({
imports: [
BrowserModule,
CommonModule,
HttpModule,
AppRoutingModule,
NgxBlogModule,
MarkdownToHtmlModule.forRoot()
],
declarations: [
AppComponent,
HomeComponent
],
providers: [
PostsService
],
declarations: [AppComponent],
providers: [ ],
bootstrap: [AppComponent],
})
export class AppModule { }
8 changes: 8 additions & 0 deletions src/app/ngx-blog/components/posts/posts.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<section>
<ng-container *ngFor='let post of posts'>
<article markdown-to-html [src]="post.file" class="posts-card" >
<h2>{{posts.title}}</h2>
<span>{{posts.description}}</span>
</article>
</ng-container>
</section>
36 changes: 36 additions & 0 deletions src/app/ngx-blog/components/posts/posts.component.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/app/ngx-blog/components/posts/posts.component.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading