~jpgleeson/piaine

86dbf8b54573b67c074f77ad3bd6a20c67c7da17 — jpgleeson 10 months ago 68ae65d + 7c3bd44
Merge remote-tracking branch 'sourcehut/master'

# Conflicts:
#	PageConsumer.cs
#	Variable.cs
2 files changed, 79 insertions(+), 10 deletions(-)

M PageConsumer.cs
M Program.cs
M PageConsumer.cs => PageConsumer.cs +32 -10
@@ 22,20 22,42 @@ namespace piaine
                    if (s[0] == '-')
                    {
                        string[] splitString = s.Split(':');
                        Variable v = new Variable(splitString[0], splitString[1]);
                        v.name = v.name.Trim();
                        v.name = v.name.Remove(0, 1);
                        v.literal = v.literal.Trim();
                        variablesInPage.Add(v);
                        if (v.name == "body")
                        
                        if (splitString[0] == "tags")
                        {
                            for (int i = currentLine + 1; i < inputLines.Count; i++)
                            string[] splitTagString = splitString[1].Split(',');
                            List<string> tagsInSplit = new List<string>();

                            for (int i = 0; i < splitTagString.Length; i++)
                            {
                                tagsInSplit.Add(splitTagString[i].Trim());
                                Console.WriteLine(splitTagString[i].Trim());
                            }
                            TagVariable tV = new TagVariable(splitString[0], tagsInSplit);
                            tV.name = tV.name.Trim();
                            tV.name = tV.name.Remove(0, 1);
                            variablesInPage.Add(tV);
                        }
                        else
                        {
                            Variable v = new Variable(splitString[0], splitString[1]);
                            v.name = v.name.Trim();
                            v.name = v.name.Remove(0, 1);
                            v.literal = v.literal.Trim();
                            variablesInPage.Add(v);

                            if (v.name == "body")
                            {
                                v.literal += "\n";
                                v.literal += inputLines[i];
                                for (int i = currentLine + 1; i < inputLines.Count; i++)
                                {
                                     v.literal += "\n";
                                     v.literal += inputLines[i];
                                }
                                break;
                            }
                            break;
                        }
                        
                        
                        currentLine++;
                    }
                }

M Program.cs => Program.cs +47 -0
@@ 19,6 19,7 @@ namespace piaine

            StreamWriter[] files = new StreamWriter[sourceDirectory.Count];
            List<Post> posts = new List<Post>();
            List<string> tags = new List<string>();

            //For some reason parser needs to be used outside of the foreach scope for the source files. I've no idea why, but this works right now.
            Parser parser = new Parser(scanner.scanTokens());


@@ 49,6 50,11 @@ namespace piaine
                post.date = pageConsumer.getPageDate();
                post.tags = pageConsumer.getPageTags();

                foreach (string tag in post.tags)
                {
                    tags.Add(tag);
                }

                if (pageConsumer.getPageTemplate() != null)
                {
                    inputString = readTemplateFile(pageConsumer.getPageTemplate());


@@ 108,6 114,10 @@ namespace piaine
            }

            Console.WriteLine("Files generated. Press any key to exit.");
            foreach (string eachtag in tags)
            {
                Console.WriteLine(eachtag);
            }

            Console.ReadKey();
        }


@@ 182,5 192,42 @@ namespace piaine

            Console.WriteLine("Atom feed written.");
        }

        static void buildTagFiles(List<Post> posts)
        {
            string inputString = readTemplateFile("index.html");
            Scanner scanner = new Scanner(inputString);
            Parser parser = new Parser(scanner.scanTokens());
            List<string> outputStrings = new List<string>();
            var indexFile = File.Create("output/index.html");

            posts.Sort((x, y) => x.date.CompareTo(y.date));

            posts.Reverse();

            List<Post> justPosts = new List<Post>();

            foreach (Post p in posts)
            {
                if (p.typeOfPage == pageType.post)
                {
                    justPosts.Add(p);
                }
            }

            //Make an index here.
            outputStrings = parser.writeVariablesInSource(inputString, justPosts);

            StreamWriter indexWriter = new StreamWriter(indexFile);

            foreach (string st in outputStrings)
            {
                indexWriter.WriteLine(st);
            }

            indexWriter.Flush();

            Console.WriteLine("Index written.");
        }
    }
}