Merge pull request #991 from dhzzy88/master
HTMLs added two links: the next page,the last page
This commit is contained in:
100
zh/a_herf.go
Normal file
100
zh/a_herf.go
Normal file
@@ -0,0 +1,100 @@
|
||||
package main
|
||||
|
||||
import(
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
)
|
||||
func dir()([]string,error) {
|
||||
path, err := os.Getwd()
|
||||
if err != nil {
|
||||
fmt.Println("err is:", err)
|
||||
}
|
||||
log.Println(path)
|
||||
path =path +"/*.html"
|
||||
|
||||
fmt.Println(path)
|
||||
files,err := filepath.Glob(path)
|
||||
var s =make([]string,len(files))
|
||||
var head uint8 =0
|
||||
for _,k :=range files {
|
||||
filename := filepath.Base(k)
|
||||
head=filename[0]
|
||||
if (head < 52) {
|
||||
s = append(s, filename)
|
||||
fmt.Println(filename)
|
||||
}
|
||||
}
|
||||
sort.Strings(s)
|
||||
|
||||
return s,err
|
||||
}
|
||||
|
||||
|
||||
func htmlfile(filename string,next_path string,last_path string)(error){
|
||||
file,err:= os.OpenFile("./"+filename,os.O_RDWR,0666)
|
||||
if err !=nil{
|
||||
fmt.Println("something is err :",err)
|
||||
}
|
||||
defer file.Close()
|
||||
var add_string1 string = "\n<a href=\"./"+next_path+"\">下一页</a>\n"
|
||||
var add_string2 string = "\n<a href=\"./"+last_path+"\">下一页</a>\n"
|
||||
file.Seek(1,2)
|
||||
_,err=file.WriteString(add_string1)
|
||||
_,err=file.WriteString(add_string2)
|
||||
file.Seek(0,0)
|
||||
if(err!=nil){
|
||||
fmt.Println("err:",err)
|
||||
}
|
||||
var f =make([]byte,50000)
|
||||
_,err=file.Read(f)
|
||||
if(err!=nil){
|
||||
fmt.Println("error:",err)
|
||||
}
|
||||
//fmt.Println(string(f))
|
||||
return err
|
||||
}
|
||||
func nextandlast(filenames []string,index int )(filename string,next_path string,last_path string){
|
||||
fmt.Println(index," ---",index+1)
|
||||
filename = filenames[index]
|
||||
if(0<index && index<len(filenames)-1) {
|
||||
next_path = filenames[index+1]
|
||||
last_path = filenames[index-1]
|
||||
}else if(index==0){
|
||||
next_path =filenames[index+1]
|
||||
last_path = filenames[len(filenames)-1]
|
||||
}else if(index==len(filenames)){
|
||||
next_path =filenames[0]
|
||||
last_path =filenames[index-1]
|
||||
}else{
|
||||
return
|
||||
}
|
||||
return filename,next_path,last_path
|
||||
}
|
||||
|
||||
|
||||
func main(){
|
||||
files,err:=dir()
|
||||
if(err!=nil){
|
||||
fmt.Println(err)
|
||||
}
|
||||
//fmt.Println(files)
|
||||
// var tmp string ="\0"
|
||||
for i, v :=range files{
|
||||
if(v!=""){
|
||||
fmt.Println(v)
|
||||
filename,next_path,last_path :=nextandlast(files,i)
|
||||
err:=htmlfile(filename,next_path,last_path)
|
||||
if(err!=nil){
|
||||
fmt.Println("err=",err)
|
||||
}else if(v==""){
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
log.Println("end")
|
||||
|
||||
return
|
||||
}
|
||||
29
zh/a_href.py
Normal file
29
zh/a_href.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import os
|
||||
import os.path
|
||||
path =os.getcwd()
|
||||
listdir =os.listdir(path)
|
||||
html =[]
|
||||
for dirs in listdir:
|
||||
if (dirs[-1]=="l") and (dirs[0].isnumeric()):
|
||||
html.append(dirs)
|
||||
|
||||
html.sort()
|
||||
print(html)
|
||||
k=0
|
||||
for item in html:
|
||||
if 0<k<len(html)-1:
|
||||
next_path = html[k+1]
|
||||
l_path =html[k-1]
|
||||
elif k==0:
|
||||
l_path =html[-1]
|
||||
next_path=html[1]
|
||||
else:
|
||||
l_path =html[-2]
|
||||
next_path=html[0]
|
||||
k=0
|
||||
with open(item,"a") as f:
|
||||
f.write('\n<a href="./'+next_path+'">下一页</a>\n')
|
||||
f.write('\n<a href="./'+l_path+'">上一页</a>\n')
|
||||
|
||||
k = k+1
|
||||
print("end!")
|
||||
Reference in New Issue
Block a user