Sha256: ead9b9932f2bd23abd54b884b132149823fa8bf77ea1565c49d46fd8e19b1521

Contents?: true

Size: 880 Bytes

Versions: 8

Compression:

Stored size: 880 Bytes

Contents

#!/usr/bin/env ruby
# encoding: utf-8
require 'soywiki'

def inbound_links_to?(file, page_title)
  return false unless File.file?(file)
  return false if (file =~ /(\.swo|\.swp)$/ || file =~ /^\./)
  body =   File.read(file)
  body =~ /[\A\s\n\b]#{page_title.gsub(".", "\.")}\b/
end

target_page = ARGV.first

if target_page.namespaced?
  namespace, page = *target_page.split(".")
  # find all files in this namespace
  xs = Dir.glob(File.join("#{namespace}", "*")).select do |file|
    inbound_links_to?(file, target_page) || inbound_links_to?(file, ".#{page}")
  end
  ys = Dir.glob(File.join("**", '*')).select do |file|
    inbound_links_to?(file, target_page) 
  end
  (xs + ys).uniq.sort.
    each {|x| puts x.to_page_title}
else
  Dir.glob(File.join("**", '*')).select do |file|
    inbound_links_to?(file, target_page)
  end.
    each {|file| puts file.to_page_title}
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
soywiki-0.0.9 bin/soywiki-pages-linking-in
soywiki-0.0.8 bin/soywiki-pages-linking-in
soywiki-0.0.7 bin/soywiki-pages-linking-in
soywiki-0.0.6 bin/soywiki-pages-linking-in
soywiki-0.0.5 bin/soywiki-pages-linking-in
soywiki-0.0.4 bin/soywiki-pages-linking-in
soywiki-0.0.3 bin/soywiki-pages-linking-in
soywiki-0.0.2 bin/soywiki-pages-linking-in