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

前端提取标题生成 TOC,支持帖子以及 Wiki 页面 #791

Merged
merged 8 commits into from
Mar 6, 2017

Conversation

Martin91
Copy link
Contributor

@Martin91 Martin91 commented Oct 30, 2016

电脑端帖子效果

screen shot 2017-03-05 at 1 43 35 am

手机端帖子效果点击 TOC 后效果

screen shot 2017-03-05 at 1 44 06 am

电脑端 Wiki 页划过 TOC 后效果

screen shot 2017-03-05 at 2 02 25 am

手机端 Wiki 页点击 TOC 后效果

screen shot 2017-03-05 at 2 03 03 am

iPad 端 Wiki 页点击 TOC 后效果

screen shot 2017-03-05 at 2 12 25 am

@huobazi
Copy link
Contributor

huobazi commented Oct 30, 2016

👍 wiki 很需要这个功能 直接放到 wiki 的第一屏顶部正好。

@greatghoul
Copy link

TOC 放的这个位置感觉挺难受的,要不要考虑下 Dropbox Paper 那样的形式?

@Martin91
Copy link
Contributor Author

Martin91 commented Oct 30, 2016

@huobazi 后边可以再考虑,如果这个 PR 合并了,后边再基于这个代码做实现。
@greatghoul 嗯嗯,我自己也觉得不是很好,不过我没用过 Dropbox Paper,是如下一样的吗?这个 Sections Navigator 应该是下拉展开的吧?我可以尝试实现一个类似的。
image

@@ -19,6 +19,7 @@ window.TopicView = Backbone.View.extend
"click a.follow": "follow"
"click a.bookmark": "bookmark"
"click .btn-move-page": "scrollPage"
"click .catalogue_item": "scrollPage"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catalogue_item -> catalogue-item

CSS className 用中横线

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,这个没有留意,后边改下。

@@ -303,6 +303,26 @@
a.btn-move-page { color: #666; }
}

#topic-catalogue {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catalogue 用 catalog 是不是准确一些?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,特地查了下,catalog 是美式英语常用表达,catalogue 是非美式的常用表达。

@@ -0,0 +1,20 @@
# 提取目录功能
#
module CatalogueExtraction
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catalogable

保持 concerns 统一的命名方式

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,这个也是疏忽了,后边修改。

@@ -0,0 +1,28 @@
# 从 HTML 片段中提取目录树
#
module CatalogueExtractor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个东西,应该放到 html::pipeline 的流程里面

@huacnlee
Copy link
Member

这个事情我一定会合并的,不过 @Martin91 需要先讲转换流程放入 HTML::Pipeline 的流程里面,而不是单独的转换

@huacnlee
Copy link
Member

不过,还有个事情是,TOC 放在 Topic 里面意义不大,反而是 WIKI 更需要

@huacnlee
Copy link
Member

貌似可以直接利用 redcarpet 已有的功能:

vmg/redcarpet#255

@Martin91
Copy link
Contributor Author

Martin91 commented Nov 1, 2016

@huacnlee 我觉得是帖子太长的话,有个 TOC 会更方便。

HTML::Pipeline 我有考虑过,只是感觉不是很适合,因为现有的 Pipeline 是在处理输出最终 HTML 的,TOC 的生成没法跟现有的 Pipeline 集成吧。还是说起一个新的 Pipeline,就单独处理 TOC。

原来 Redcarpet 已经有现成的功能了,我原来找了好久没找到(orz....原来搜的时候没加 TOC... 孤陋寡闻了),那我还是先尝试用现有的吧。不重复造轮子。不过这些改动最快也要周末才能接着搞了,工作日一般没时间。

@huacnlee
Copy link
Member

huacnlee commented Nov 1, 2016

如果要放到帖子里面,可以增加一个 [TOC] 的图标,默认折叠 TOC 内容,点击按钮展开

@Martin91
Copy link
Contributor Author

Martin91 commented Nov 1, 2016

@huacnlee ok,这个跟我想的差不多。

@huacnlee
Copy link
Member

huacnlee commented Nov 2, 2016

或许可以更简单点,直接用 JS 实现

https://ruby-china.org/topics/17028

 $(document).ready(function(){
      $(".markdown h2,h3,h4,h5,h6").each(function(i,item){
        var tag = $(item).get(0).localName;
        $(item).attr("id","wow"+i);
        $("#category").append('<a class="new'+tag+'" href="#wow'+i+'">'+$(this).text()+'</a></br>');
        $(".newh2").css("margin-left",0);
        $(".newh3").css("margin-left",20);
        $(".newh4").css("margin-left",40);
        $(".newh5").css("margin-left",60);
        $(".newh6").css("margin-left",80);
      });
 });

@greatghoul
Copy link

image
image

dropbox paper 的 toc 在左侧,平常就是一些不影响阅读的线框,鼠标移过时会显示出 toc。

@lihuazhang
Copy link
Contributor

https://ruby-china.org/topics/32333 现在很多帖子 都靠截图来给大纲了。。 看来这个功能其实还挺重要的。

@NeverMin
Copy link
Contributor

这个功能很赞:

  1. 鼓励发表有深度有营养的文章
  2. 帮助读者定位感兴趣的章节
  3. (帖子和wiki都需要)与 markdown 理念一致: 专注写作

这是我的看法, 谢谢

@huacnlee
Copy link
Member

@Martin91 继续哦

@Martin91
Copy link
Contributor Author

Martin91 commented Feb 28, 2017 via email

@codecov
Copy link

codecov bot commented Mar 4, 2017

Codecov Report

Merging #791 into master will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #791   +/-   ##
=======================================
  Coverage   98.53%   98.53%           
=======================================
  Files         142      142           
  Lines        6228     6228           
=======================================
  Hits         6137     6137           
  Misses         91       91

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2759c8e...eb9e195. Read the comment docs.

@Martin91 Martin91 changed the title 提取生成文章的目录树,并且在页面上展示导航 前端提取标题生成 TOC,支持帖子以及 Wiki 页面 Mar 4, 2017
@Martin91
Copy link
Contributor Author

Martin91 commented Mar 4, 2017

@huobazi @greatghoul @huacnlee @lihuazhang @NeverMin 我重写了 PR,纯前端的方式解决了问题,可以直接看 PR 里的 comment,麻烦大家提供意见。

@NeverMin
Copy link
Contributor

NeverMin commented Mar 5, 2017

Hi @Martin91, 感谢, 纯前端的解决方案很好, 所以我毫不犹豫就直接手动合并到产线上. 除此之外, 可能在正式合并时需要统一在 双引号 和 单引号 @huacnlee .

https://zammad.org.cn/wiki/zammad-documentation

@Martin91
Copy link
Contributor Author

Martin91 commented Mar 5, 2017

@NeverMin 感谢支持,我刚刚更新了代码,对细节样式进行了调整,可以参考截图。
screen shot 2017-03-05 at 12 24 43 pm
screen shot 2017-03-05 at 12 25 23 pm

@NeverMin
Copy link
Contributor

NeverMin commented Mar 5, 2017

@Martin91
Nice job. 是否考虑将 TOC 改为 Contents / 目錄 / 目录 (参考 wikipedia), 如:
<a href="#toc" title="TOC" id='toc-link'>[<%= t('contents') %> +]</a>

@Martin91
Copy link
Contributor Author

Martin91 commented Mar 5, 2017

image
image
image
@NeverMin ?

@NeverMin
Copy link
Contributor

NeverMin commented Mar 5, 2017

@Martin91 Perfect 👍

@huacnlee
Copy link
Member

huacnlee commented Mar 6, 2017

还得最后整理一下,我刚合并了一个将 Page 剥离出去的 PR,然后冲突了。

Wiki 有关的内容剥离到 ruby-china/homeland-wiki 了

@Martin91
Copy link
Contributor Author

Martin91 commented Mar 6, 2017 via email

@huacnlee huacnlee merged commit 4eae629 into ruby-china:master Mar 6, 2017
@huacnlee
Copy link
Member

huacnlee commented Mar 6, 2017

@Martin91 不用了,我先 Revert 那边的 PR 了,那个还有部分没完成

@Martin91
Copy link
Contributor Author

Martin91 commented Mar 6, 2017 via email

huacnlee added a commit that referenced this pull request Mar 6, 2017
@huacnlee
Copy link
Member

huacnlee commented Mar 6, 2017

@Martin91 我调整了一下实现,你可以看看我修改的内容

huacnlee added a commit that referenced this pull request Mar 6, 2017
@Martin288
Copy link

@huacnlee 现在那个回复里边有问题,每个回复都有了个目录按钮?

@Martin288
Copy link

Martin288 commented Mar 6, 2017

@huacnlee 还有个问题就是,现在的目录下拉菜单按钮那里,鼠标得移到三角标才能点击下拉,放在“目录”两个字上却不行,小小的体验细节。

image

@huacnlee
Copy link
Member

huacnlee commented Mar 6, 2017

https://ruby-china.org/topics/19436

没有你说的问题 @Martin288

@Martin288
Copy link

@huacnlee 是的,另外的这篇有,估计是特殊场景,你看看
https://ruby-china.org/topics/32451

@NeverMin
Copy link
Contributor

NeverMin commented Mar 6, 2017 via email

@huacnlee
Copy link
Member

huacnlee commented Mar 6, 2017

@Martin288 @NeverMin 已修复

@NeverMin
Copy link
Contributor

NeverMin commented Mar 6, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants