Skip to content

Commit

Permalink
chore: make markdown linter happy and refactor script
Browse files Browse the repository at this point in the history
  • Loading branch information
killme2008 committed Jul 10, 2024
1 parent 3f57c09 commit 6de0ca9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
1 change: 1 addition & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
uses: nosborn/github-action-markdown-cli@v3.2.0
with:
files: "./**/*.md"
ignore_files: "./**/df_function.md"
config_file: .markdownlint.yaml
- name: Check typos
uses: crate-ci/typos@master
49 changes: 26 additions & 23 deletions docs/misc/update_functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
## Usage: ruby misc/update_functions.rb [nightly | v0.x]
# encoding: utf-8
require 'net/http'
require 'rdoc'

scalar_functions = {
:name => "DataFusion Scalar Functions",
Expand All @@ -22,6 +21,29 @@
datafusion_functions = [scalar_functions, agg_functions, window_functions]


def process_headlines(line)
## Add a level of headlines
if line =~ /^\s*(#+)\s/
replacement = "#{$1}#"
## We don't want to render the function names in right menu bar
replacement += "#" if replacement.length >= 4
line.gsub! $1, replacement
end
line
end

def fix_links(line)
## Fix link: #a_b_c -> #a-b-c
line.gsub!(/(#[a-zA-Z0-9_]+)\)/) { |match| match.gsub("_", "-") }
## Fix link: a_b_c.md -> #a-b-c
line.gsub!(/\]\(([a-zA-Z0-9_]+\.md)\)/) { |match|
match.gsub("_", "-").gsub(".md", "").gsub("](", "](#")
}

line
end


File.open("temp.md", "w") do |f|
f.puts("# DataFusion Functions")
f.puts("This page is generated from the Apache DataFusion project's documents:")
Expand All @@ -40,29 +62,10 @@
markdown = Net::HTTP.get(uri).force_encoding(Encoding::UTF_8)

lines = markdown.split(/\n/)
lines.map! do |line|
## Add a level of headlines
if line =~ /^\s*(#+)\s/
replacement = "#{$1}#"

if replacement.length >= 4
replacement += "#"
end
line.gsub! $1, replacement
end
## Fix link: #a_b_c -> #a-b-c
if line =~ /(#[a-zA-Z0-9_]+)\)/
link = $1.to_s
replacement = link.gsub("_", "-")
line.gsub! link, replacement
end
## Fix link: a_b_c.md -> #a-b-c
if line =~ /\]\(([a-zA-Z0-9_]+\.md)\)/
link = $1.to_s
replacement = "#" + link.gsub("_", "-").gsub("\.md", "")
line.gsub! link, replacement
end

lines.map! do |line|
line = process_headlines(line)
line = fix_links(line)
line
end

Expand Down
2 changes: 1 addition & 1 deletion docs/nightly/en/reference/sql/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ select compact_table("test");

## Time and Date

DataFusion [Time and Date Functon](./df_functions#time-and-date-functions).
DataFusion [Time and Date Function](./df_functions#time-and-date-functions).

### INTERVAL

Expand Down

0 comments on commit 6de0ca9

Please sign in to comment.