Skip to content

Commit

Permalink
* Fix #1:[New Feature]在本文中引用其他目录的文章
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayin committed Jan 30, 2015
1 parent 2fb028b commit 9fe8cdd
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 24 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ see [Demo](http://meizhuo.github.io/silentor/)
![图片说明|right](./img/xxx.jpg)
```

### 在本文中引用其他目录的文章

详情:参考这个[issue#1](https://github.com/Jayin/silentor/issues/1)

例子:
```markdown

//引用当前目录下的other.md
[其他目录文章标题](other.md) //推荐
[其他目录文章标题](./other.md)

//引用上一级目录App目录下的other.md PS:不支持多次上级操作
[其他目录文章标题](../App/other.md)

//引用任意目录下other.md
[其他目录文章标题](__ROOT__/path/to/file/other.md) //推荐

```

开发指南
===

Expand Down
6 changes: 6 additions & 0 deletions p/Authors/jayin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
jayin
-------

#### projects

- [ETips](__ROOT__/projects/ETips.md)
30 changes: 25 additions & 5 deletions p/home.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ Features
* 支持语法高亮
* 友好的移动端支持

使用
===
使用指南
=======

### 第一步:配置根目录的config.json
```json
{
Expand All @@ -37,9 +38,6 @@ git push origin gh-pages

see [Demo](http://meizhuo.github.io/silentor/)

开发指南
===

### 设置图片
我们约定在根目录下的img/下放置所有图片文件

Expand All @@ -60,6 +58,28 @@ see [Demo](http://meizhuo.github.io/silentor/)
![图片说明|right](./img/xxx.jpg)
```

### 在本文中引用其他目录的文章

详情:参考这个[issue#1](https://github.com/Jayin/silentor/issues/1)

例子:
```markdown

//引用当前目录下的other.md
[其他目录文章标题](other.md) //推荐
[其他目录文章标题](./other.md)

//引用上一级目录App目录下的other.md PS:不支持多次上级操作
[其他目录文章标题](../App/other.md)

//引用任意目录下other.md
[其他目录文章标题](__ROOT__/path/to/file/other.md) //推荐

```

开发指南
===

### 根目录下的404.md就是找不页面时显示的内容
若有需要,可以改写里面的内容

Expand Down
5 changes: 5 additions & 0 deletions p/projects/ETips.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ETips
----

- see [Authors](../Authors/jayin.md)
- see [other apps](index.md)
2 changes: 1 addition & 1 deletion p/projects/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Projects


## ETips
## [ETips](./ETips.md)
>五邑大学校园生活助手应用!对接学生子系统,一键导入课程表,轻松查成绩算绩点;对接邑大图书馆,查个人借阅信息,图书检索/收藏;校园资讯模块,校内信息动态掌握在手;对接校园服务,查空课室/电费,看邑大新闻超级方便;内置个人便签,记录生活点滴/学习笔记

Expand Down
52 changes: 34 additions & 18 deletions vendor/blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @param baseUrl 基准url
*/
function load(selector, file_path, isSidebar, baseUrl) {
baseUrl = baseUrl || blog_base;
baseUrl = baseUrl || blog_base;
isSidebar = isSidebar || false;

p_url = baseUrl + file_path;
Expand Down Expand Up @@ -66,8 +66,24 @@
}

//main page
if (!isAbsolute(url) && !isSidebar && isMarkdownFile(url) ) {
$element.attr('href', '?' + getPageBase(cur_md_path) + url);
if (!isAbsolute(url) && !isSidebar && isMarkdownFile(url)) {
var new_url = getPageBase(cur_md_path);
//上一级目录
if (url.indexOf('../') == 0) {
new_url = new_url.substring(0, new_url.length - 1);
if (new_url.indexOf('/') != -1) {
new_url = new_url.slice(0, new_url.lastIndexOf('/') + 1) + url.slice(3, url.length);
} else {
new_url = url.slice(3, url.length);
}
} else if (url.indexOf('__ROOT__') == 0) {
//文章根目录`p/`下
new_url = url.replace('__ROOT__/', '');
} else {
//当前目录
new_url = new_url + url.replace('./', '');
}
$element.attr('href', '?' + new_url);
}
});
//main-page
Expand All @@ -77,32 +93,32 @@
$('title').text(mainTitle);

//图片位置
$.each($(selector).find('img'),function(index,item){
$.each($(selector).find('img'), function(index, item) {
var alt = $(item).attr('alt') || '';
if(alt.indexOf('|left') != -1){
if (alt.indexOf('|left') != -1) {
$(item).addClass('img-left');
}else if(alt.indexOf('|right') != -1){
} else if (alt.indexOf('|right') != -1) {
$(item).addClass('img-right');
}else{
} else {
$(item).addClass('img-center');
}
});
}
//sidebar
if (isSidebar){
if (isSidebar) {
//round avatar
$(selector).find('img').first().addClass('avatar');
//add animation in item
$.each($(selector).find('li'),function(index,item){
$(item).addClass('sidebar-item');
$.each($(selector).find('li'), function(index, item) {
$(item).addClass('sidebar-item');
});
}

}).fail(function(err) {
if (err.status === 404) {
console.log('404-->' + '/' + app_name + '/');
console.log($._c);
if(file_path ==='footer.md'){
if (file_path === 'footer.md') {
console.log('没有找到footer.md! 建议在p/目录下建立footer.md 文件来添加底部信息!');
return;
}
Expand Down Expand Up @@ -130,13 +146,13 @@
read_config(function() {
//加载侧边菜单栏
load('#sidebar-page', 'sidebar.md', true);
load('#main-page-footer','footer.md');
load('#main-page-footer', 'footer.md');
//加载主内容页
if(location.search.indexOf('&') !== -1){
cur_md_path = location.search.slice(1, location.search.indexOf('&'));
}else{
cur_md_path = location.search.slice(1, location.search.length);
}
if (location.search.indexOf('&') !== -1) {
cur_md_path = location.search.slice(1, location.search.indexOf('&'));
} else {
cur_md_path = location.search.slice(1, location.search.length);
}
if (cur_md_path === '') {
load('#main-page', 'home.md');
console.log("load main~");
Expand All @@ -151,4 +167,4 @@
main();


})(jQuery);
})(jQuery);

0 comments on commit 9fe8cdd

Please sign in to comment.