summaryrefslogtreecommitdiff
path: root/blog/content/util
diff options
context:
space:
mode:
Diffstat (limited to 'blog/content/util')
-rw-r--r--blog/content/util/indexer.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/blog/content/util/indexer.cpp b/blog/content/util/indexer.cpp
new file mode 100644
index 0000000..b072633
--- /dev/null
+++ b/blog/content/util/indexer.cpp
@@ -0,0 +1,48 @@
+//filename title date tags
+#include <dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <cstdio>
+#include <cstring>
+#include <algorithm>
+#include <functional>
+#include <string>
+#include <vector>
+#define stripr(s) s[strlen(s)-1]=='\n'?s[strlen(s)-1]=0:0
+std::vector<std::string> fn;
+char buf1[65536],buf2[65536],buf3[65536];
+int main()
+{
+ struct dirent* pd;DIR* pdir;
+ pdir=opendir("/var/www/html/blog/content");
+ while((pd=readdir(pdir))!=NULL)
+ {
+ std::string s(pd->d_name);
+ if(s.length()<4)continue;
+ if(s.substr(s.length()-4)==".txt")
+ fn.push_back(s.substr(0,s.length()-4));
+ }
+ closedir(pdir);
+ std::sort(fn.begin(),fn.end(),std::greater<std::string>());
+ FILE *f,*rf;
+ f=fopen("/var/www/html/blog/content/pindex","w");
+ for(size_t i=0;i<fn.size();++i)
+ {
+ puts(("/var/www/html/blog/content/"+fn[i]+".txt").c_str());
+ struct stat st;struct tm* mt;
+ stat(("/var/www/html/blog/content/"+fn[i]+".txt").c_str(),&st);
+ mt=localtime(&st.st_mtime);
+ rf=fopen(("/var/www/html/blog/content/"+fn[i]+".txt").c_str(),"r");
+ fgets(buf1,65536,rf);stripr(buf1);
+ fgets(buf2,65536,rf);stripr(buf2);
+ fgets(buf3,65536,rf);stripr(buf3);
+ if(strstr(buf2,"WIP")){puts(" SKIPPED");continue;}
+ fprintf(f,"%s\t",fn[i].c_str());
+ fprintf(f,"%s\t",buf1);
+ fprintf(f,"%s/%d-%02d-%02d\t",buf2,mt->tm_year+1900,mt->tm_mon+1,mt->tm_mday);
+ fprintf(f,"%s\n",buf3);
+ fclose(rf);
+ }
+ fclose(f);
+}