-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
👍 wiki 很需要这个功能 直接放到 wiki 的第一屏顶部正好。 |
TOC 放的这个位置感觉挺难受的,要不要考虑下 Dropbox Paper 那样的形式? |
@huobazi 后边可以再考虑,如果这个 PR 合并了,后边再基于这个代码做实现。 |
app/assets/javascripts/topics.coffee
Outdated
@@ -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" |
There was a problem hiding this comment.
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 用中横线
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的,这个没有留意,后边改下。
app/assets/stylesheets/front.scss
Outdated
@@ -303,6 +303,26 @@ | |||
a.btn-move-page { color: #666; } | |||
} | |||
|
|||
#topic-catalogue { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catalogue 用 catalog 是不是准确一些?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catalogable
保持 concerns 统一的命名方式
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的,这个也是疏忽了,后边修改。
lib/catalogue_extractor.rb
Outdated
@@ -0,0 +1,28 @@ | |||
# 从 HTML 片段中提取目录树 | |||
# | |||
module CatalogueExtractor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个东西,应该放到 html::pipeline 的流程里面
这个事情我一定会合并的,不过 @Martin91 需要先讲转换流程放入 HTML::Pipeline 的流程里面,而不是单独的转换 |
不过,还有个事情是,TOC 放在 Topic 里面意义不大,反而是 WIKI 更需要 |
貌似可以直接利用 redcarpet 已有的功能: |
@huacnlee 我觉得是帖子太长的话,有个 TOC 会更方便。 HTML::Pipeline 我有考虑过,只是感觉不是很适合,因为现有的 Pipeline 是在处理输出最终 HTML 的,TOC 的生成没法跟现有的 Pipeline 集成吧。还是说起一个新的 Pipeline,就单独处理 TOC。 原来 Redcarpet 已经有现成的功能了,我原来找了好久没找到(orz....原来搜的时候没加 TOC... 孤陋寡闻了),那我还是先尝试用现有的吧。不重复造轮子。不过这些改动最快也要周末才能接着搞了,工作日一般没时间。 |
如果要放到帖子里面,可以增加一个 [TOC] 的图标,默认折叠 TOC 内容,点击按钮展开 |
@huacnlee ok,这个跟我想的差不多。 |
或许可以更简单点,直接用 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);
});
}); |
https://ruby-china.org/topics/32333 现在很多帖子 都靠截图来给大纲了。。 看来这个功能其实还挺重要的。 |
这个功能很赞:
这是我的看法, 谢谢 |
@Martin91 继续哦 |
不好意思,这段时间一忙就没跟进,这周内搞定,我觉得 Jason 的方案很适合,我到时候实现下!
Jason Lee <notifications@github.com>于2017年2月28日 周二下午2:26写道:
… @Martin91 <https://github.com/Martin91> 继续哦
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#791 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACxCpMOu4kSxOItj-Wy9GgvGhtN2xcz-ks5rg74OgaJpZM4KkUFI>
.
|
8a5ee24
to
08cc10d
Compare
Codecov Report
@@ 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.
|
@huobazi @greatghoul @huacnlee @lihuazhang @NeverMin 我重写了 PR,纯前端的方式解决了问题,可以直接看 PR 里的 comment,麻烦大家提供意见。 |
@NeverMin 感谢支持,我刚刚更新了代码,对细节样式进行了调整,可以参考截图。 |
@Martin91 |
@Martin91 Perfect 👍 |
还得最后整理一下,我刚合并了一个将 Page 剥离出去的 PR,然后冲突了。 Wiki 有关的内容剥离到 ruby-china/homeland-wiki 了 |
好的,我回头处理一下
Jason Lee <notifications@github.com>于2017年3月6日 周一上午10:02写道:
… 还得最后整理一下,我刚合并了一个将 Page 剥离出去的 PR,然后冲突了。
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#791 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACxCpHiYa7nl9ZKw5D78FBuqgQIOtvmaks5ri2k0gaJpZM4KkUFI>
.
|
@Martin91 不用了,我先 Revert 那边的 PR 了,那个还有部分没完成 |
行的,非常感谢
Jason Lee <notifications@github.com>于2017年3月6日 周一上午10:16写道:
… @Martin91 <https://github.com/Martin91> 不用了,我先 Revert 那边的 PR 了,那个还有部分没完成
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#791 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACxCpNlWUiyUoZmeo2K4fnbiHsnMYvF0ks5ri2x-gaJpZM4KkUFI>
.
|
@Martin91 我调整了一下实现,你可以看看我修改的内容 |
@huacnlee 现在那个回复里边有问题,每个回复都有了个目录按钮? |
@huacnlee 还有个问题就是,现在的目录下拉菜单按钮那里,鼠标得移到三角标才能点击下拉,放在“目录”两个字上却不行,小小的体验细节。 |
@huacnlee 是的,另外的这篇有,估计是特殊场景,你看看 |
@huacnlee <https://github.com/huacnlee>
对于 https://ruby-china.org/topics/19436
我另外发了你一张图片, Firefox 上正常, 移动版本和 Chrome 有问题.
2017-03-06 11:40 GMT+08:00 洪泽钦 <notifications@github.com>:
… @huacnlee <https://github.com/huacnlee> 是的,另外的这篇有,估计是特殊场景,你看看
https://ruby-china.org/topics/32451
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#791 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACqveCMP9sHJptmwc5yCtAUVLLfASopyks5ri4BJgaJpZM4KkUFI>
.
|
@Martin288 @NeverMin 已修复 |
Hi All,
我看到 ruby-china 有更新, 包括移动端都 div 也有调整. Nice job.
…-Never
2017-03-06 11:50 GMT+08:00 Jason Lee <notifications@github.com>:
@Martin288 <https://github.com/Martin288> @NeverMin
<https://github.com/NeverMin> 已修复
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#791 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACqveBE2b2mpB4LNSK80xQvwTK51U1omks5ri4J6gaJpZM4KkUFI>
.
|
电脑端帖子效果
手机端帖子效果点击 TOC 后效果
电脑端 Wiki 页划过 TOC 后效果
手机端 Wiki 页点击 TOC 后效果
iPad 端 Wiki 页点击 TOC 后效果